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 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();
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;
}
}