From 9a70c609e00f952584a356b4ddc8fa3240438a12 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 12 Jan 2011 06:01:07 +0000 Subject: BLI_dynstr_vappendf() was cutting off the last character when allocating strings. --- source/blender/blenlib/intern/BLI_dynstr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source/blender/blenlib/intern/BLI_dynstr.c') diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index e683c5c016f..cdf74ae6b5b 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -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; -- cgit v1.2.3