Enlightenment CVS committal

Author  : barbieri
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/canvas


Modified Files:
        evas_object_textblock.c 


Log Message:
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.


===================================================================
RCS file: /cvs/e/e17/libs/evas/src/lib/canvas/evas_object_textblock.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -3 -r1.146 -r1.147
--- evas_object_textblock.c     15 Feb 2008 14:45:31 -0000      1.146
+++ evas_object_textblock.c     5 Mar 2008 21:30:22 -0000       1.147
@@ -266,13 +266,13 @@
        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 @@
        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 @@
    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 @@
    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 @@
    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;
 }
 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to