summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2013-10-10 17:06:37 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-11 19:15:29 +0200
commit7a47aebe9ed41d6cd9c9bcd45758d4d553668e99 (patch)
tree4f1f9c59691c384a47aa6eadf2a719795f37e21f /src/corelib
parentf9889534d16290262eced02bc9c9ed1a9afb8fac (diff)
Let QLoggingCategory::defaultCategory return a pointer
The pointer can be null. Going trough the reference invokes undefined behavior here. Change-Id: Ia84e4e732cdcbbaee0f5f0679765d18069ea8b2d Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qlogging.cpp2
-rw-r--r--src/corelib/io/qloggingcategory.cpp15
-rw-r--r--src/corelib/io/qloggingcategory.h2
3 files changed, 13 insertions, 6 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 063e94069f..b9b5173881 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -927,7 +927,7 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex
#ifndef QT_BOOTSTRAPPED
// qDebug, qWarning, ... macros do not check whether category is enabled
if (!context.category || (strcmp(context.category, "default") == 0)) {
- if (QLoggingCategory *defaultCategory = &QLoggingCategory::defaultCategory()) {
+ if (QLoggingCategory *defaultCategory = QLoggingCategory::defaultCategory()) {
if (!defaultCategory->isEnabled(msgType))
return;
}
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 6c5df1e8e7..2ef392c209 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -244,12 +244,19 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
*/
/*!
- Returns the category \c "default" that is used e.g. by qDebug(), qWarning(),
- qCritical(), qFatal().
+ Returns a pointer to the global category \c "default" that
+ is used e.g. by qDebug(), qWarning(), qCritical(), qFatal().
+
+ \note The returned pointer may be null during destruction of
+ static objects.
+
+ \note Ownership of the category is not transferred, do not
+ \c delete the returned pointer.
+
*/
-QLoggingCategory &QLoggingCategory::defaultCategory()
+QLoggingCategory *QLoggingCategory::defaultCategory()
{
- return *qtDefaultCategory();
+ return qtDefaultCategory();
}
/*!
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h
index 35da04c8f2..6009226127 100644
--- a/src/corelib/io/qloggingcategory.h
+++ b/src/corelib/io/qloggingcategory.h
@@ -72,7 +72,7 @@ public:
// allows usage of both factory method and variable in qCX macros
QLoggingCategory &operator()() { return *this; }
- static QLoggingCategory &defaultCategory();
+ static QLoggingCategory *defaultCategory();
typedef void (*CategoryFilter)(QLoggingCategory*);
static CategoryFilter installFilter(CategoryFilter);