forked from enlightenment/efl
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
This commit is contained in:
parent
43ed37904a
commit
4bd8fdaeeb
|
@ -266,13 +266,13 @@ _strbuf_append(char *s, const char *s2, int *len, int *alloc)
|
||||||
int talloc;
|
int talloc;
|
||||||
|
|
||||||
talloc = ((tlen + 31) >> 5) << 5;
|
talloc = ((tlen + 31) >> 5) << 5;
|
||||||
ts = realloc(s, talloc + 1);
|
ts = realloc(s, talloc);
|
||||||
if (!ts) return s;
|
if (!ts) return s;
|
||||||
s = ts;
|
s = ts;
|
||||||
*alloc = talloc;
|
*alloc = talloc;
|
||||||
}
|
}
|
||||||
strcpy(s + *len, s2);
|
strcpy(s + *len, s2);
|
||||||
*len = tlen;
|
*len += l2;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,21 +290,21 @@ _strbuf_append_n(char *s, char *s2, int n, int *len, int *alloc)
|
||||||
char *p;
|
char *p;
|
||||||
for (p = s2; (l2 < n) && (*p != 0); p++, l2++);
|
for (p = s2; (l2 < n) && (*p != 0); p++, l2++);
|
||||||
}
|
}
|
||||||
tlen = *len + l2;
|
tlen = *len + l2 + 1;
|
||||||
if (tlen > *alloc)
|
if (tlen > *alloc)
|
||||||
{
|
{
|
||||||
char *ts;
|
char *ts;
|
||||||
int talloc;
|
int talloc;
|
||||||
|
|
||||||
talloc = ((tlen + 31) >> 5) << 5;
|
talloc = ((tlen + 31) >> 5) << 5;
|
||||||
ts = realloc(s, talloc + 1);
|
ts = realloc(s, talloc);
|
||||||
if (!ts) return s;
|
if (!ts) return s;
|
||||||
s = ts;
|
s = ts;
|
||||||
*alloc = talloc;
|
*alloc = talloc;
|
||||||
}
|
}
|
||||||
strncpy(s + *len, s2, l2);
|
strncpy(s + *len, s2, l2);
|
||||||
*len = tlen;
|
*len += l2;
|
||||||
s[tlen] = 0;
|
s[*len] = 0;
|
||||||
return s;
|
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 < 0) pos = 0;
|
||||||
else if (pos > *len) pos = *len;
|
else if (pos > *len) pos = *len;
|
||||||
l2 = strlen(s2);
|
l2 = strlen(s2);
|
||||||
tlen = *len + l2;
|
tlen = *len + l2 + 1;
|
||||||
if (tlen > *alloc)
|
if (tlen > *alloc)
|
||||||
{
|
{
|
||||||
char *ts;
|
char *ts;
|
||||||
int talloc;
|
int talloc;
|
||||||
|
|
||||||
talloc = ((tlen + 31) >> 5) << 5;
|
talloc = ((tlen + 31) >> 5) << 5;
|
||||||
ts = realloc(s, talloc + 1);
|
ts = realloc(s, talloc);
|
||||||
if (!ts) return s;
|
if (!ts) return s;
|
||||||
s = ts;
|
s = ts;
|
||||||
*alloc = talloc;
|
*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(tbuf, s + pos, *len - pos);
|
||||||
strncpy(s + pos, s2, l2);
|
strncpy(s + pos, s2, l2);
|
||||||
strncpy(s + pos + l2, tbuf, *len - pos);
|
strncpy(s + pos + l2, tbuf, *len - pos);
|
||||||
*len = tlen;
|
*len += l2;
|
||||||
s[tlen] = 0;
|
s[*len] = 0;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,19 +356,20 @@ _strbuf_remove(char *s, int p, int p2, int *len, int *alloc)
|
||||||
tbuf = alloca(*len - p2 + 1);
|
tbuf = alloca(*len - p2 + 1);
|
||||||
strcpy(tbuf, s + p2);
|
strcpy(tbuf, s + p2);
|
||||||
strcpy(s + p, tbuf);
|
strcpy(s + p, tbuf);
|
||||||
tlen = *len - (p2 - p);
|
tlen = *len - (p2 - p) + 1;
|
||||||
if (tlen < ((*alloc >> 5) << 15))
|
if (tlen < ((*alloc >> 5) << 15))
|
||||||
{
|
{
|
||||||
char *ts;
|
char *ts;
|
||||||
int talloc;
|
int talloc;
|
||||||
|
|
||||||
talloc = ((tlen + 31) >> 5) << 5;
|
talloc = ((tlen + 31) >> 5) << 5;
|
||||||
ts = realloc(s, talloc + 1);
|
ts = realloc(s, talloc);
|
||||||
if (!ts) return s;
|
if (!ts) return s;
|
||||||
s = ts;
|
s = ts;
|
||||||
*alloc = talloc;
|
*alloc = talloc;
|
||||||
}
|
}
|
||||||
*len = tlen;
|
*len += (p2 - p);
|
||||||
|
s[*len] = 0;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue