]> git.neil.brown.name Git - edlib.git/commitdiff
Fix text_round_len usage in text_ref_same
authorNeilBrown <neil@brown.name>
Sun, 22 Nov 2015 02:41:07 +0000 (13:41 +1100)
committerNeilBrown <neil@brown.name>
Sun, 22 Nov 2015 02:41:07 +0000 (13:41 +1100)
text_round_usage must be called with a len *less* than the len
of the string.

Thanks to valgrind for finding this.

Signed-off-by: NeilBrown <neil@brown.name>
doc-text.c

index d458b618f6c6f5b0fe8f6bebe8a2b3503145ba81..d5ab67c86992026296680c7dcc60ecce256048a3 100644 (file)
@@ -903,8 +903,16 @@ static wint_t text_step(struct doc *d, struct mark *m, bool forward, bool move)
 static int text_ref_same(struct text *t, struct doc_ref *r1, struct doc_ref *r2)
 {
        if (r1->c == r2->c) {
+               if (r1->o == r2->o)
+                       return 1;
                if (r1->c == NULL)
-                       return r1->o == r2->o;
+                       return 0;
+               /* if references are in the middle of a UTF-8 encoded
+                * char, accept as same if it is same char
+                */
+               if (r1->o == r1->c->end ||
+                   r2->o == r2->c->end)
+                       return 0;
                return text_round_len(r1->c->txt, r1->o) ==
                        text_round_len(r1->c->txt, r2->o);
        }