Skip to content

Don't crash when a log message has no category (fixes #251) - #255

Open
munzzyy wants to merge 1 commit into
flipperdevices:devfrom
munzzyy:fix/logger-null-category-crash
Open

Don't crash when a log message has no category (fixes #251)#255
munzzyy wants to merge 1 commit into
flipperdevices:devfrom
munzzyy:fix/logger-null-category-crash

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #251.

Logger::messageOutput() decides whether a line belongs in the in-app log viewer with:

const auto filterWithoutCategory = !strcmp(context.category, "default");

context.category is a raw const char* and isn't always set. Qt's qErrnoWarning() builds a default-constructed QMessageLogContext and leaves category null, and that context reaches the installed handler unchanged — qt_message_print() forwards it as-is. Since this handler is installed process-wide (both application.cpp and cli.cpp call qInstallMessageHandler), it also receives Qt's own internal warnings, so a null category is reachable.

That's the crash in #251. From the qflipper_gdb.txt attached to that issue:

#0  __strcmp_avx2 () at ../sysdeps/x86_64/multiarch/strcmp-avx2.S:283
#1  Logger::messageOutput (type=QtCriticalMsg, context=@...: {version = 2, line = 0,
    file = 0x0, function = 0x0, category = 0x0}, msg=...) at ../backend/logger.cpp:80
#2  qt_message_print (...)
#3  qt_message_output (...)
#4  qErrnoWarning (msg=... "inotify_add_watch(%ls) failed:") at global/qlogging.cpp:1955

category = 0x0 right there in the frame, and the caller is qErrnoWarning from QInotifyFileSystemWatcherEngine::addPaths — KDE's directory watcher hitting the inotify watch limit while the firmware file dialog walks directories. That matches the reporter's "crashes when browsing files" exactly.

The fix treats a null category the same as "default", which is what Qt does internally for this same check (isDefaultCategory() in qlogging.cpp is !category || strcmp(category, "default") == 0). Filtering behaviour doesn't change: uncategorised messages were already kept out of the log viewer, and they're still written to stderr and the log file a few lines above this check.

I couldn't build qFlipper here, so I verified this from the source and the coredump rather than by running it. To confirm on a machine that can: reproduce #251 (browse for a firmware file on a KDE system near its fs.inotify.max_user_watches limit) and check that it no longer crashes and the message still lands in the saved log.

Logger::messageOutput() does strcmp(context.category, "default") to
decide whether a line belongs in the in-app log viewer. context.category
is a raw const char* and isn't always set: Qt's qErrnoWarning() builds a
default-constructed QMessageLogContext and leaves category null, and that
context reaches the installed handler unchanged. The handler is installed
process-wide in both the GUI and the CLI, so it sees Qt's internal
warnings too.

That's the crash in issue flipperdevices#251. The attached coredump has strcmp called
from Logger::messageOutput at logger.cpp:80 with
context = {version = 2, line = 0, file = 0x0, function = 0x0,
category = 0x0}, reached via qErrnoWarning("inotify_add_watch(%ls)
failed:") from QInotifyFileSystemWatcherEngine::addPaths while KDE's
directory watcher was walking the file dialog.

Treat a null category the same as "default", which is what Qt's own
isDefaultCategory() does. Filtering behaviour is unchanged.

Signed-off-by: Cole Munz <colemunz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qflipper crashes when browsing files

1 participant