Commit c7bfa47b05

c7bfa47b05e52fa740902edd445c54ba91e72fb1

parent: 5d668724e1

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