BLI_dynstr_vappendf() was cutting off the last character when allocating strings.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jan 2011 06:01:07 +0000 (06:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jan 2011 06:01:07 +0000 (06:01 +0000)
source/blender/blenlib/intern/BLI_dynstr.c

index e683c5c016f94877db387bece5ef812a02f60524..cdf74ae6b5bef3279a26a8b7a63f38333e46f0c7 100644 (file)
@@ -110,7 +110,7 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args)
                if(len == sizeof(fixedmessage))
                        message= fixedmessage;
                else
-                       message= MEM_callocN(sizeof(char)*(len+1), "BLI_dynstr_appendf");
+                       message= MEM_callocN(sizeof(char) * len, "BLI_dynstr_appendf");
 
                /* cant reuse the same args, so work on a copy */
                va_copy(args_cpy, args);
@@ -130,13 +130,14 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args)
                                break;
                        }
                }
-               else if(retval > len) {
+               else if(retval >= len) {
                        /* in C99 the actual length required is returned */
                        if(message != fixedmessage)
                                MEM_freeN(message);
                        message= NULL;
 
-                       len= retval;
+                       /* retval doesnt include \0 terminator */
+                       len= retval + 1;
                }
                else
                        break;