diff options
author | Egmont Koblinger <egmont@gmail.com> | 2019-10-11 12:47:15 +0200 |
---|---|---|
committer | Egmont Koblinger <egmont@gmail.com> | 2019-10-11 12:56:01 +0200 |
commit | 4c832530d9301f6e86d09640f22c3246406fd6ae (patch) | |
tree | 8f1c6920cb2ca6302b1693a3183e19d485dceccd | |
parent | da0b9a03b34a7054acffec83bc4be66f4e0dc1a9 (diff) | |
download | vte-0.52.4.tar.gz |
ring: Fix an incorrect assertion0.52.4
An assertion in the rewrap code incorrectly assumed that the last line
of the ring is always hard wrapped (i.e. ends in an explicit newline).
Rewrapping when the last line is soft wrapped and the cursor stands here
after the last nonempty cell resulted in a crash.
https://gitlab.gnome.org/GNOME/vte/issues/181
(cherry picked from commit a6cb948d2c352056b79e04efd372f88f84b8e0a1)
-rw-r--r-- | src/ring.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ring.cc b/src/ring.cc index d03b1559..7d549541 100644 --- a/src/ring.cc +++ b/src/ring.cc @@ -1107,8 +1107,6 @@ _vte_frozen_row_text_offset_to_column (VteRing *ring, } else records[1].text_start_offset = _vte_stream_head (ring->text_stream); - g_assert(offset->text_offset >= records[0].text_start_offset && offset->text_offset < records[1].text_start_offset); - g_string_set_size (buffer, records[1].text_start_offset - records[0].text_start_offset); if (!_vte_stream_read (ring->text_stream, records[0].text_start_offset, buffer->str, buffer->len)) return FALSE; @@ -1116,6 +1114,12 @@ _vte_frozen_row_text_offset_to_column (VteRing *ring, if (G_LIKELY (buffer->len && buffer->str[buffer->len - 1] == '\n')) buffer->len--; + /* Now that we've chopped off the likely trailing newline (which is only rarely missing, + * if the ring ends in a soft wrapped line; see bug 181), the position we're about to + * locate can be anywhere in the string, including just after its last character, + * but not beyond that. */ + g_assert(offset->text_offset >= records[0].text_start_offset && offset->text_offset <= records[0].text_start_offset + buffer->len); + row = _vte_ring_index(ring, position); /* row and buffer now contain the same text, in different representation */ @@ -1123,7 +1127,7 @@ _vte_frozen_row_text_offset_to_column (VteRing *ring, /* count the number of characters for the given UTF-8 text offset */ off = offset->text_offset - records[0].text_start_offset; num_chars = 0; - for (i = 0; i < off && i < buffer->len; i++) { + for (i = 0; i < off; i++) { if ((buffer->str[i] & 0xC0) != 0x80) num_chars++; } |