From 56b6a5924008ab5cdbae36e9662eddba923acd5e Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Fri, 31 Jul 2009 08:50:07 +1000 Subject: Fixed corrupt testlogs on Windows and other places where vsnprintf is not C99-compliant. C99 says vsnprintf returns >= `size' when not enough memory was available. In practice, on Windows, glibc < 2.0.6, and probably plenty of other places it returns -1 instead. Reviewed-by: Rhys Weatherley --- src/testlib/qtestcase.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index e44be9c..1dae828 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -834,11 +834,12 @@ int qt_asprintf(char **str, const char *format, ...) res = qvsnprintf(*str, size, format, ap); va_end(ap); (*str)[size - 1] = '\0'; - if (res < size) { - // We succeeded or fatally failed + if (res >= 0 && res < size) { + // We succeeded break; } - // buffer wasn't big enough, try again + // buffer wasn't big enough, try again. + // Note, we're assuming that a result of -1 is always due to running out of space. size *= 2; if (size > MAXSIZE) { break; -- cgit v0.12