Fix mix of new[] / malloc in QTest::toHexRepresentation

toHexRepresentation is used in QTest::toString(), whose results are
deallocated with free(). So we shouldn't allocate with new[].

Change-Id: I3e9d35b3f28a1b9bfe740a13b5daa414b67853c6
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
This commit is contained in:
Thiago Macieira 2014-01-20 22:15:09 -08:00 committed by The Qt Project
parent b5241296f8
commit 57d36d3f0c

View File

@ -1893,7 +1893,7 @@ char *toHexRepresentation(const char *ba, int length)
if (length > maxLen) {
const int size = len * 3 + 4;
result = new char[size];
result = static_cast<char *>(malloc(size));
char *const forElipsis = result + size - 5;
forElipsis[0] = ' ';
@ -1901,10 +1901,9 @@ char *toHexRepresentation(const char *ba, int length)
forElipsis[2] = '.';
forElipsis[3] = '.';
result[size - 1] = '\0';
}
else {
} else {
const int size = len * 3;
result = new char[size];
result = static_cast<char *>(malloc(size));
result[size - 1] = '\0';
}