[vte/vte-0-56] ring: Fix an incorrect assertion



commit 73a890ed0d725331314d2fc0ac12583e8051e77b
Author: Egmont Koblinger <egmont gmail com>
Date:   Fri Oct 11 12:47:15 2019 +0200

    ring: Fix an incorrect assertion
    
    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)

 src/ring.cc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/ring.cc b/src/ring.cc
index 731b1bc2..a1ef059f 100644
--- a/src/ring.cc
+++ b/src/ring.cc
@@ -1067,9 +1067,6 @@ Ring::frozen_row_text_offset_to_column(row_t position,
        } else
                records[1].text_start_offset = _vte_stream_head (m_text_stream);
 
-       g_assert_cmpuint(offset->text_offset, >=, records[0].text_start_offset);
-       g_assert_cmpuint(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(m_text_stream, records[0].text_start_offset, buffer->str, buffer->len))
                return false;
@@ -1077,6 +1074,13 @@ Ring::frozen_row_text_offset_to_column(row_t position,
        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_cmpuint(offset->text_offset, >=, records[0].text_start_offset);
+        g_assert_cmpuint(offset->text_offset, <=, records[0].text_start_offset + buffer->len);
+
        row = index(position);
 
        /* row and buffer now contain the same text, in different representation */
@@ -1084,7 +1088,7 @@ Ring::frozen_row_text_offset_to_column(row_t position,
        /* 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++;
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]