summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Roquetto <rafael.roquetto.qnx@kdab.com>2013-12-16 16:10:22 -0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-17 19:05:50 +0100
commitce9ece3b56d45b00bbca14042fe4d60df35de191 (patch)
treebbe33d811d69c776bd63dabe8d3eb47e93118044
parente7d39c929204f631d11e2f87b2f8e972b1abbf6e (diff)
Fix qlocale_blackberry buffer initialization
The QVarLengthArray inside qlocale_blackberry.cpp was being preallocated with 512 bytes, that means internally it could grow up to 512 bytes using the stack before switching to the heap, but its actual semantic size was still 0. After qt_safe_read(... buffer.data() ...) was being called, data was written to the QVarLengthArray buffer, but its semantic size was still 0, since it was not resized or anything. This triggered an assertion when buffer[bytes] = '\0' was assigned, since 'bytes' > buffer.size() ( == 0) despite buffer.capacity() == 512. Change-Id: I5503ee9b02413794f67730700fba05a4c194d465 Reviewed-by: Mehdi Fekari <mfekari@blackberry.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r--src/corelib/tools/qlocale_blackberry.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/tools/qlocale_blackberry.cpp b/src/corelib/tools/qlocale_blackberry.cpp
index c2c3476b0a..0165780634 100644
--- a/src/corelib/tools/qlocale_blackberry.cpp
+++ b/src/corelib/tools/qlocale_blackberry.cpp
@@ -193,15 +193,15 @@ QByteArray QBBSystemLocaleData::readPpsValue(const char *ppsObject, int ppsFd)
// Using QVarLengthArray means the first try (of size == 512) uses a buffer on the stack - no allocation necessary.
// Hopefully that covers most use cases.
int bytes;
- QVarLengthArray<char, 512> buffer;
+ QVarLengthArray<char, 512> buffer(512);
for (;;) {
errno = 0;
- bytes = qt_safe_read(ppsFd, buffer.data(), buffer.capacity() - 1);
- const bool bufferIsTooSmall = (bytes == -1 && errno == EMSGSIZE && buffer.capacity() < MAX_PPS_SIZE);
+ bytes = qt_safe_read(ppsFd, buffer.data(), buffer.size() - 1);
+ const bool bufferIsTooSmall = (bytes == -1 && errno == EMSGSIZE && buffer.size() < MAX_PPS_SIZE);
if (!bufferIsTooSmall)
break;
- buffer.resize(qMin(buffer.capacity()*2, MAX_PPS_SIZE));
+ buffer.resize(qMin(buffer.size()*2, MAX_PPS_SIZE));
}
// This method is called in the ctor(), so do not use qWarning to log warnings