Commit fd7996d9df

fd7996d9df6b56ed7311f09c86369e1cc31c7585

parent: f41c0519f9

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2021-03-02 16:55 UTC

room: Fix a panic on debug builds in the local echo rendering logic

Layout: unified · split

src/room/mod.rs +5 −6
@@ -853,20 +853,19 @@ impl MatrixRoom {
853 let line_contains_uuid = |l: &BufferLine| l.tags().contains(&uuid_tag); 853 let line_contains_uuid = |l: &BufferLine| l.tags().contains(&uuid_tag);
854 854
855 let mut lines = buffer.lines(); 855 let mut lines = buffer.lines();
856 let mut first_line = lines.rfind(line_contains_uuid); 856 let mut current_line = lines.rfind(line_contains_uuid);
857 857
858 // We go in reverse order here since we also use rfind(). We got from 858 // We go in reverse order here since we also use rfind(). We got from
859 // the bottom of the buffer to the top since we're expecting these 859 // the bottom of the buffer to the top since we're expecting these
860 // lines to be freshly printed and thus at the bottom. 860 // lines to be freshly printed and thus at the bottom.
861 let mut line_num = rendered.content.lines.len() - 1; 861 let mut line_num = rendered.content.lines.len();
862 862
863 while let Some(line) = &first_line { 863 while let Some(line) = &current_line {
864 line_num -= 1;
864 let rendered_line = &rendered.content.lines[line_num]; 865 let rendered_line = &rendered.content.lines[line_num];
865 866
866 line.set_message(&rendered_line.message); 867 line.set_message(&rendered_line.message);
867 868 current_line = lines.next_back().filter(line_contains_uuid);
868 line_num -= 1;
869 first_line = lines.next_back().filter(line_contains_uuid);
870 } 869 }
871 } 870 }
872 871