diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-01-24 15:58:00 +0000 |
---|---|---|
committer | Chris Wilson <cpwilson@src.gnome.org> | 2007-01-24 15:58:00 +0000 |
commit | a8d1c20f2b3b5d92d2fb50f3e35a28b11c8660ed (patch) | |
tree | 361e669e67b7c62b0dbb1176d0fd8c58ce85e04c /src/vteaccess.c | |
parent | 1fcb3ef370accd3b59eeae5538cf05244dd215f1 (diff) | |
download | vte-a8d1c20f2b3b5d92d2fb50f3e35a28b11c8660ed.tar.gz |
Valgrind pointed out a couple of places where we tried to access before
2007-01-24 Chris Wilson <chris@chris-wilson.co.uk>
* src/vteaccess.c: (vte_terminal_accessible_text_modified):
Valgrind pointed out a couple of places where we tried to
access before the start of the string.
svn path=/trunk/; revision=1516
Diffstat (limited to 'src/vteaccess.c')
-rw-r--r-- | src/vteaccess.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/vteaccess.c b/src/vteaccess.c index 4b6db012..097ea5aa 100644 --- a/src/vteaccess.c +++ b/src/vteaccess.c @@ -483,8 +483,9 @@ vte_terminal_accessible_text_modified(VteTerminal *terminal, gpointer data) } /* Check if we just backspaced over a space. */ - if ((olen == offset) && (old[caret_offset] == ' ') && - (old_snapshot_caret == (priv->snapshot_caret + 1))) { + if ((olen == offset) && + (caret_offset < olen && old[caret_offset] == ' ') && + (old_snapshot_caret == (priv->snapshot_caret + 1))) { glong bsp_olen = caret_offset + 1; priv->snapshot_text->str = old; @@ -498,22 +499,25 @@ vte_terminal_accessible_text_modified(VteTerminal *terminal, gpointer data) /* At least one of them had better have more data, right? */ if ((offset < olen) || (offset < clen)) { - gchar *op, *cp; /* Back up from both end points until we find the *last* point * where they differed. - * Start by looking at the terminating NUL byte */ - op = old + olen; - cp = current + clen; - do { - op = g_utf8_prev_char (op); - cp = g_utf8_prev_char (cp); - if ((op <= old + offset) || (cp <= current + offset)) { - break; - } - } while (g_utf8_get_char (op) == g_utf8_get_char (cp)); - /* recompute the respective lengths */ - olen = op - old; - clen = cp - current; + */ + if (olen > offset && clen > offset) { + /* Start by looking at the terminating NUL byte */ + gchar *op = old + olen; + gchar *cp = current + clen; + do { + op = g_utf8_prev_char (op); + cp = g_utf8_prev_char (cp); + if ((op <= old + offset) || + (cp <= current + offset)) { + break; + } + } while (g_utf8_get_char (op) == g_utf8_get_char (cp)); + /* recompute the respective lengths */ + olen = op - old; + clen = cp - current; + } /* At least one of them has to have text the other * doesn't. */ g_assert((clen > offset) || (olen > offset)); |