[fractal/clippy-ci: 20/25] Fix stack overflow when switching to bold room
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/clippy-ci: 20/25] Fix stack overflow when switching to bold room
- Date: Fri, 21 Feb 2020 20:12:38 +0000 (UTC)
commit ca2da1e1a527fbf0efeefc5a829a187edf369d88
Author: Sonja Heinze <sonjaleaheinze gmail com>
Date: Mon Feb 17 14:36:42 2020 +0100
Fix stack overflow when switching to bold room
Consider the following: the find_visible_index() recursion in the room
history is initiated with only one message loaded in that room. That
message is not detected as in sight.
Then, before this commit, the recursion would never hit a base case and
therefore lead to a stack overflow. This commit fixes that bug and makes
sure that no similar bugs will be implemented in the future.
fractal-gtk/src/widgets/room_history.rs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 911c25b4..cc27416b 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -131,7 +131,7 @@ impl List {
let sw = self.view.get_scrolled_window();
let visible_index = match get_rel_position(&sw, &self.list[0]) {
RelativePosition::InSight => Some(0),
- _ => self.find_visible_index((1, len - 1)),
+ _ => self.find_visible_index((0, len - 1)),
};
if let Some(visible) = visible_index {
indices.push(visible);
@@ -149,6 +149,11 @@ impl List {
}
fn find_visible_index(&self, range: (usize, usize)) -> Option<usize> {
+ /* Looks for a message widget in sight among all elements in rows.list.list of RoomHistory
+ whose corresponding index lies in the closed interval [range.0, range.1]. */
+ if range.0 > range.1 {
+ return None;
+ }
let middle_index = (range.0 + range.1) / 2;
let element = &self.list[middle_index];
let scrolled_window = self.view.get_scrolled_window();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]