summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2009-07-30 22:50:07 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2009-07-31 00:30:32 (GMT)
commit56b6a5924008ab5cdbae36e9662eddba923acd5e (patch)
tree349047243e50e8ca210991b60b5d76714049cbfa
parent0ba7569ab7911bf65b6321ad65ac979d9d034c2b (diff)
downloadQt-56b6a5924008ab5cdbae36e9662eddba923acd5e.zip
Qt-56b6a5924008ab5cdbae36e9662eddba923acd5e.tar.gz
Qt-56b6a5924008ab5cdbae36e9662eddba923acd5e.tar.bz2
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
-rw-r--r--src/testlib/qtestcase.cpp7
1 files 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;