StdStrBuf::AppendFormatV: Pass copied va_list to vsnprintf so the second iteration of the while loop does not crash

stable-5.3
Martin Plicht 2013-01-13 11:03:49 +01:00 committed by Nicolas Hake
parent a202001564
commit ca1c4538ee
1 changed files with 10 additions and 1 deletions

View File

@ -238,7 +238,16 @@ void StdStrBuf::AppendFormatV(const char *szFmt, va_list args)
// Grow
Grow(512);
// Try output
iBytes = vsnprintf(getMPtr(iStart), getLength() - iStart, szFmt, args);
va_list args_copy;
#ifdef va_copy
va_copy(args_copy, args);
#else
args_copy = args;
#endif
iBytes = vsnprintf(getMPtr(iStart), getLength() - iStart, szFmt, args_copy);
#ifdef va_copy
va_end(args_copy);
#endif
}
while (iBytes < 0 || (unsigned int)(iBytes) >= getLength() - iStart);
// Calculate real length, if vsnprintf didn't return anything of value