From 96513c6d0799e60769a7159a9a4d4642af599cdd Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 31 Mar 2019 13:25:43 +0200 Subject: [PATCH] Fix null pointer dereference in QtMessageHandler function The `QMessageLogContext` is only filled out in debug builds. Release builds will have null pointers in `file` and `line`. This causes any error attempted to be logged to result in a null pointer dereference. Since we never use debug builds anyway, simply removing the uses of `file` and `line` makes sense. Github issue https://github.com/OpenVR-Advanced-Settings/OpenVR-AdvancedSettings/issues/139 --- src/utils/setup.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/utils/setup.cpp b/src/utils/setup.cpp index 95c7e59..a5ea435 100644 --- a/src/utils/setup.cpp +++ b/src/utils/setup.cpp @@ -7,28 +7,27 @@ void mainQtMessageHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg ) { + // context contains null pointers on release builds. Cast to get rid of + // unreferenced formal parameter warnings. + static_cast( context ); + QByteArray localMsg = msg.toLocal8Bit(); switch ( type ) { case QtDebugMsg: - LOG( DEBUG ) << localMsg.constData() << " (" << context.file << ":" - << context.line << ")"; + LOG( DEBUG ) << localMsg.constData(); break; case QtInfoMsg: - LOG( INFO ) << localMsg.constData() << " (" << context.file << ":" - << context.line << ")"; + LOG( INFO ) << localMsg.constData(); break; case QtWarningMsg: - LOG( WARNING ) << localMsg.constData() << " (" << context.file << ":" - << context.line << ")"; + LOG( WARNING ) << localMsg.constData(); break; case QtCriticalMsg: - LOG( ERROR ) << localMsg.constData() << " (" << context.file << ":" - << context.line << ")"; + LOG( ERROR ) << localMsg.constData(); break; case QtFatalMsg: - LOG( FATAL ) << localMsg.constData() << " (" << context.file << ":" - << context.line << ")"; + LOG( FATAL ) << localMsg.constData(); break; } }