Bug 798873 Patch 3 - flex_string fix for Windows vsnprintf r=jesup

This commit is contained in:
Ethan Hugg 2012-10-17 18:57:57 -07:00
parent dd2bac76ff
commit be98e21abb

View File

@ -178,6 +178,14 @@ void flex_string_sprintf(flex_string *fs, const char *format, ...) {
vsnprintf_result = vsnprintf(fs->buffer + fs->string_length, fs->buffer_length - fs->string_length, format, ap);
va_end(ap);
/* Special case just for Windows where vsnprintf is broken
and returns -1 if buffer too large unless you size it 0. */
if (vsnprintf_result < 0) {
va_start(ap, format);
vsnprintf_result = vsnprintf(NULL, 0, format, ap);
va_end(ap);
}
if (fs->string_length + vsnprintf_result >= fs->buffer_length) {
/* Buffer overflow, resize */
flex_string_check_alloc(fs, fs->string_length + vsnprintf_result + 1);