From 8a0c88f71b756de1f2960dc1f1ffda8de4235e99 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 7 Mar 2015 18:32:42 +0100 Subject: [PATCH] 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 instead. --- src/xbus/utils.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/xbus/utils.h b/src/xbus/utils.h index 89a9be108..f1e9bfd7a 100644 --- a/src/xbus/utils.h +++ b/src/xbus/utils.h @@ -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 = ""; + + 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(); }