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
This commit is contained in:
Vasily
2019-03-31 14:19:05 +02:00
committed by username223
parent bcdf87b0f5
commit 96513c6d07
+9 -10
View File
@@ -7,28 +7,27 @@ void mainQtMessageHandler( QtMsgType type,
const QMessageLogContext& context, const QMessageLogContext& context,
const QString& msg ) const QString& msg )
{ {
// context contains null pointers on release builds. Cast to get rid of
// unreferenced formal parameter warnings.
static_cast<void>( context );
QByteArray localMsg = msg.toLocal8Bit(); QByteArray localMsg = msg.toLocal8Bit();
switch ( type ) switch ( type )
{ {
case QtDebugMsg: case QtDebugMsg:
LOG( DEBUG ) << localMsg.constData() << " (" << context.file << ":" LOG( DEBUG ) << localMsg.constData();
<< context.line << ")";
break; break;
case QtInfoMsg: case QtInfoMsg:
LOG( INFO ) << localMsg.constData() << " (" << context.file << ":" LOG( INFO ) << localMsg.constData();
<< context.line << ")";
break; break;
case QtWarningMsg: case QtWarningMsg:
LOG( WARNING ) << localMsg.constData() << " (" << context.file << ":" LOG( WARNING ) << localMsg.constData();
<< context.line << ")";
break; break;
case QtCriticalMsg: case QtCriticalMsg:
LOG( ERROR ) << localMsg.constData() << " (" << context.file << ":" LOG( ERROR ) << localMsg.constData();
<< context.line << ")";
break; break;
case QtFatalMsg: case QtFatalMsg:
LOG( FATAL ) << localMsg.constData() << " (" << context.file << ":" LOG( FATAL ) << localMsg.constData();
<< context.line << ")";
break; break;
} }
} }