summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale_blackberry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qlocale_blackberry.cpp')
-rw-r--r--src/corelib/tools/qlocale_blackberry.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/corelib/tools/qlocale_blackberry.cpp b/src/corelib/tools/qlocale_blackberry.cpp
index 48faa73070..c2c3476b0a 100644
--- a/src/corelib/tools/qlocale_blackberry.cpp
+++ b/src/corelib/tools/qlocale_blackberry.cpp
@@ -60,7 +60,7 @@ static const char ppsRegionLocalePath[] = "/pps/services/locale/settings";
static const char ppsLanguageLocalePath[] = "/pps/services/confstr/_CS_LOCALE";
static const char ppsHourFormatPath[] = "/pps/system/settings";
-static const size_t ppsBufferSize = 256;
+static const int MAX_PPS_SIZE = 16000;
QBBSystemLocaleData::QBBSystemLocaleData()
: languageNotifier(0)
@@ -186,9 +186,24 @@ QByteArray QBBSystemLocaleData::readPpsValue(const char *ppsObject, int ppsFd)
if (!ppsObject || ppsFd == -1)
return result;
- char buffer[ppsBufferSize];
+ // PPS objects are of unknown size, but must be read all at once.
+ // Relying on the file size may not be a good idea since the size may change before reading.
+ // Let's try with an initial size (512), and if the buffer is too small try with bigger one,
+ // until we succeed or until other non buffer-size-related error occurs.
+ // 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;
+ 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);
+ if (!bufferIsTooSmall)
+ break;
+
+ buffer.resize(qMin(buffer.capacity()*2, MAX_PPS_SIZE));
+ }
- int bytes = qt_safe_read(ppsFd, buffer, ppsBufferSize - 1);
// This method is called in the ctor(), so do not use qWarning to log warnings
// if qt_safe_read fails to read the pps file
// since the user code may install a message handler that invokes QLocale API again
@@ -202,7 +217,7 @@ QByteArray QBBSystemLocaleData::readPpsValue(const char *ppsObject, int ppsFd)
pps_decoder_t ppsDecoder;
pps_decoder_initialize(&ppsDecoder, 0);
- if (pps_decoder_parse_pps_str(&ppsDecoder, buffer) == PPS_DECODER_OK) {
+ if (pps_decoder_parse_pps_str(&ppsDecoder, buffer.data()) == PPS_DECODER_OK) {
pps_decoder_push(&ppsDecoder, 0);
const char *ppsBuff;
if (pps_decoder_get_string(&ppsDecoder, ppsObject, &ppsBuff) == PPS_DECODER_OK) {