summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEl Mehdi Fekari <mfekari@blackberry.com>2013-11-20 13:43:38 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-20 18:14:59 (GMT)
commit350c60358810db14989cbee2252d47a13d4fe68f (patch)
tree97db09b450213c97d8c25aa2d63a1d1038e7c96d
parent995676a9e7d3462e10cadfd57ef7f66b4dce75d5 (diff)
downloadQt-350c60358810db14989cbee2252d47a13d4fe68f.zip
Qt-350c60358810db14989cbee2252d47a13d4fe68f.tar.gz
Qt-350c60358810db14989cbee2252d47a13d4fe68f.tar.bz2
QLocale: Fix infinite loop in error case
QBBSystemLocaleData emits qwarnings when it fails to open or read a pps object. If the user code installs a message handler that will invoke QLocale API again (i.e QDate, QDateTime, ...) then this will cause an infinite loop, where the QBBSystemLocaleData ctor() is calling itself. This patch logs the QBBSystemLocale's warnings to stderr and skips the Qt message handler. Cherry-picked: qtbase/1e446fc99167a992b1a8342168b6254f43b097fe Change-Id: Iff99973532e0cba752854e325d0cd987765547d9 Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
-rw-r--r--src/corelib/tools/qlocale_blackberry.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/corelib/tools/qlocale_blackberry.cpp b/src/corelib/tools/qlocale_blackberry.cpp
index 1df6627..44bf133 100644
--- a/src/corelib/tools/qlocale_blackberry.cpp
+++ b/src/corelib/tools/qlocale_blackberry.cpp
@@ -68,17 +68,20 @@ QBBSystemLocaleData::QBBSystemLocaleData()
, measurementNotifier(0)
, hourNotifier(0)
{
+ // Do not use qWarning to log warnings if qt_safe_open fails to open the pps file
+ // since the user code may install a message handler that invokes QLocale API again
+ // (i.e QDate, QDateTime, ...) which will cause an infinite loop.
if ((measurementFd = qt_safe_open(ppsUomPath, O_RDONLY)) == -1)
- qWarning("Failed to open uom pps, errno=%d", errno);
+ fprintf(stderr, "Failed to open uom pps, errno=%d\n", errno);
if ((regionFd = qt_safe_open(ppsRegionLocalePath, O_RDONLY)) == -1)
- qWarning("Failed to open region pps, errno=%d", errno);
+ fprintf(stderr, "Failed to open region pps, errno=%d\n", errno);
if ((languageFd = qt_safe_open(ppsLanguageLocalePath, O_RDONLY)) == -1)
- qWarning("Failed to open language pps, errno=%d", errno);
+ fprintf(stderr, "Failed to open language pps, errno=%d\n", errno);
if ((hourFd = qt_safe_open(ppsHourFormatPath, O_RDONLY)) == -1)
- qWarning("Failed to open hour format pps, errno=%d", errno);
+ fprintf(stderr, "Failed to open hour format pps, errno=%d\n", errno);
// we cannot call this directly, because by the time this constructor is
// called, the event dispatcher has not yet been created, causing the
@@ -186,8 +189,12 @@ QByteArray QBBSystemLocaleData::readPpsValue(const char *ppsObject, int ppsFd)
char buffer[ppsBufferSize];
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
+ // (i.e QDate, QDateTime, ...) which will cause a infinite loop.
if (bytes == -1) {
- qWarning("Failed to read Locale pps, errno=%d", errno);
+ fprintf(stderr, "Failed to read pps object:%s, errno=%d\n", ppsObject, errno);
return result;
}
// ensure data is null terminated