From 4bd8fdaeeb9fe080d57ce05b8137d493c82af44a Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Wed, 5 Mar 2008 21:30:22 +0000 Subject: [PATCH] Fix evas_object_textblock's strbuf implementation. Code was not tracking the real size of the allocated memory and was increasing the string size by one, so the '\0' was being accounted and the string was being truncated visually. Patch will remember the exact allocated size and just increment the string size by the added string, not including it's null-byte terminator. This is based on Cedric's BAIL patch set 'evas_object_textblock more character fix', but doing the minimum to fix the problem. PS: this code will be rewritten to share some implementation in next commit. SVN revision: 33937 --- .../src/lib/canvas/evas_object_textblock.c | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/legacy/evas/src/lib/canvas/evas_object_textblock.c b/legacy/evas/src/lib/canvas/evas_object_textblock.c index 7afd9f5ef6..f041b1c818 100644 --- a/legacy/evas/src/lib/canvas/evas_object_textblock.c +++ b/legacy/evas/src/lib/canvas/evas_object_textblock.c @@ -266,13 +266,13 @@ _strbuf_append(char *s, const char *s2, int *len, int *alloc) int talloc; talloc = ((tlen + 31) >> 5) << 5; - ts = realloc(s, talloc + 1); + ts = realloc(s, talloc); if (!ts) return s; s = ts; *alloc = talloc; } strcpy(s + *len, s2); - *len = tlen; + *len += l2; return s; } @@ -290,21 +290,21 @@ _strbuf_append_n(char *s, char *s2, int n, int *len, int *alloc) char *p; for (p = s2; (l2 < n) && (*p != 0); p++, l2++); } - tlen = *len + l2; + tlen = *len + l2 + 1; if (tlen > *alloc) { char *ts; int talloc; talloc = ((tlen + 31) >> 5) << 5; - ts = realloc(s, talloc + 1); + ts = realloc(s, talloc); if (!ts) return s; s = ts; *alloc = talloc; } strncpy(s + *len, s2, l2); - *len = tlen; - s[tlen] = 0; + *len += l2; + s[*len] = 0; return s; } @@ -319,14 +319,14 @@ _strbuf_insert(char *s, char *s2, int pos, int *len, int *alloc) else if (pos < 0) pos = 0; else if (pos > *len) pos = *len; l2 = strlen(s2); - tlen = *len + l2; + tlen = *len + l2 + 1; if (tlen > *alloc) { char *ts; int talloc; talloc = ((tlen + 31) >> 5) << 5; - ts = realloc(s, talloc + 1); + ts = realloc(s, talloc); if (!ts) return s; s = ts; *alloc = talloc; @@ -335,8 +335,8 @@ _strbuf_insert(char *s, char *s2, int pos, int *len, int *alloc) strncpy(tbuf, s + pos, *len - pos); strncpy(s + pos, s2, l2); strncpy(s + pos + l2, tbuf, *len - pos); - *len = tlen; - s[tlen] = 0; + *len += l2; + s[*len] = 0; return s; } @@ -356,19 +356,20 @@ _strbuf_remove(char *s, int p, int p2, int *len, int *alloc) tbuf = alloca(*len - p2 + 1); strcpy(tbuf, s + p2); strcpy(s + p, tbuf); - tlen = *len - (p2 - p); + tlen = *len - (p2 - p) + 1; if (tlen < ((*alloc >> 5) << 15)) { char *ts; int talloc; talloc = ((tlen + 31) >> 5) << 5; - ts = realloc(s, talloc + 1); + ts = realloc(s, talloc); if (!ts) return s; s = ts; *alloc = talloc; } - *len = tlen; + *len += (p2 - p); + s[*len] = 0; return s; }