BLI_dynstr_vappendf() was cutting off the last character when allocating strings.

This commit is contained in:
Campbell Barton
2011-01-12 06:01:07 +00:00
parent e2e5361eb2
commit 9a70c609e0

View 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;