Drawing a string longer then 255 chars wasnt working.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 13 Jul 2009 11:41:24 +0000 (11:41 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 13 Jul 2009 11:41:24 +0000 (11:41 +0000)
changes to flatten_string_append(...), probably only brecht is interested.
- It was copying from the old malloc'd buffer but never the fixed buffer - the reason >255 length strings didnt render.
- on first malloc for the FlatString allocate 512 rather then 256 chars since the fixed string is 256 chars.
- if the char was '\0' fs->pos was set to 0, not sure why since char cant be '\0' because of the loop that calls flatten_string_append, removed.

source/blender/editors/space_text/text_draw.c

index 9f8cedd569fe2fe05e0e19c2ce08926bf7f70e52..9721fbc2b9c053ea3bceb9b11cf93ce49b006b00 100644 (file)
@@ -109,22 +109,18 @@ static void flatten_string_append(FlattenString *fs, char c, int accum)
 {
        if(fs->pos>=fs->len && fs->pos>=sizeof(fs->fixedbuf)-1) {
                char *nbuf; int *naccum;
-               int olen= fs->len;
-               
-               if(olen) fs->len*= 2;
-               else fs->len= 256;
-               
+               if(fs->len) fs->len*= 2;
+               else fs->len= sizeof(fs->fixedbuf) * 2;
+
                nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf");
                naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum");
+
+               memcpy(nbuf, fs->buf, fs->pos);
+               memcpy(naccum, fs->accum, fs->pos);
                
-               if(olen) {
-                       memcpy(nbuf, fs->buf, olen);
-                       memcpy(naccum, fs->accum, olen);
-                       
-                       if(fs->buf != fs->fixedbuf) {
-                               MEM_freeN(fs->buf);
-                               MEM_freeN(fs->accum);
-                       }
+               if(fs->buf != fs->fixedbuf) {
+                       MEM_freeN(fs->buf);
+                       MEM_freeN(fs->accum);
                }
                
                fs->buf= nbuf;
@@ -134,8 +130,7 @@ static void flatten_string_append(FlattenString *fs, char c, int accum)
        fs->buf[fs->pos]= c;    
        fs->accum[fs->pos]= accum;
        
-       if(c==0) fs->pos= 0;
-       else fs->pos++;
+       fs->pos++;
 }
 
 int flatten_string(SpaceText *st, FlattenString *fs, char *in)
@@ -1336,6 +1331,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
                                UI_ThemeColor(TH_TEXT);
 
                        sprintf(linenr, "%d", i + linecount + 1);
+                       /* itoa(i + linecount + 1, linenr, 10); */ /* not ansi-c :/ */
                        text_font_draw(st, TXT_OFFSET - 7, y, linenr);
 
                        UI_ThemeColor(TH_TEXT);