Securely handle table load more subtract logic to prevent attempt to subtract with overflow panic (#189)

This commit is contained in:
ihavecoke 2024-08-29 23:29:26 +08:00 committed by GitHub
parent b6ce44c349
commit fd2f5e46f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -679,15 +679,20 @@ where
return; return;
} }
if visible_range.end >= self.delegate.rows_count() - self.delegate.load_more_threshold() { let row_count = self.delegate.rows_count();
cx.spawn(|view, mut cx| async move { let load_more_count = self.delegate.load_more_threshold();
cx.update(|cx| {
view.update(cx, |view, cx| { // Securely handle subtract logic to prevent attempt to subtract with overflow
view.delegate.load_more(cx); if row_count >= load_more_count {
if visible_range.end >= row_count - load_more_count {
cx.spawn(|view, mut cx| async move {
cx.update(|cx| {
view.update(cx, |view, cx| {
view.delegate.load_more(cx);
})
}) })
}) }).detach()
}) }
.detach();
} }
} }