mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Fix segfault in xbus logging handler
xbus logging handler assumed QMessageLogContext always had a valid file pointer which is not necessarily the case. If the file pointer is 0x0 log a file name <unknown> instead.
This commit is contained in:
committed by
Klaus Basan
parent
ac760ce9b0
commit
8a0c88f71b
@@ -32,23 +32,28 @@ class QXPlaneMessageHandler
|
||||
static void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
QByteArray localMsg = msg.toLocal8Bit();
|
||||
char *buffer = new char[64 + localMsg.size() + std::strlen(context.file)];
|
||||
QByteArray file(context.file);
|
||||
if (file.isEmpty()) file = "<unknown>";
|
||||
|
||||
int line = context.line;
|
||||
|
||||
char *buffer = new char[64 + localMsg.size() + file.size()];
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
std::sprintf(buffer, "%s:%u: Debug: %s\n", context.file, context.line, localMsg.constData());
|
||||
std::sprintf(buffer, "%s:%u: Debug: %s\n", file.constData(), line, localMsg.constData());
|
||||
XPLMDebugString(buffer);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
std::sprintf(buffer, "%s:%u: Warning: %s\n", context.file, context.line, localMsg.constData());
|
||||
std::sprintf(buffer, "%s:%u: Warning: %s\n", file.constData(), line, localMsg.constData());
|
||||
XPLMDebugString(buffer);
|
||||
break;
|
||||
default:
|
||||
case QtCriticalMsg:
|
||||
std::sprintf(buffer, "%s:%u: Error: %s\n", context.file, context.line, localMsg.constData());
|
||||
std::sprintf(buffer, "%s:%u: Error: %s\n", file.constData(), line, localMsg.constData());
|
||||
XPLMDebugString(buffer);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
std::sprintf(buffer, "%s:%u: Fatal: %s\n", context.file, context.line, localMsg.constData());
|
||||
std::sprintf(buffer, "%s:%u: Fatal: %s\n", file.constData(), line, localMsg.constData());
|
||||
XPLMDebugString(buffer);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user