From c24cdcd67186f136914cdc69fa05accd3faf8a02 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Sat, 28 Feb 2026 09:44:27 +0100 Subject: [PATCH] fix: Fix -Wanalyzer-deref-before-check warning in cmd_ac_complete Adding an explicit NULL check for 'input' at the start of cmd_ac_complete to prevent a potential crash and resolve a GCC static analyzer warning. Quirk Explanation: The analyzer found a "deref-before-check" warning for: `if ((strncmp(input, "/", 1) == 0) && (!strchr(input, ' ')))` The analyzer interpreted 'strchr(input, ' ')' as a point where the validity of 'input' is being questioned (a "check"), even though it is actually checking the return value. This is due to GCC's internal model of certain standard string functions having a 'nonnull' attribute or being categorized as pointer "interrogations" in its state machine. Because 'strncmp' dereferences 'input' earlier in the same line, the analyzer saw a logical contradiction: "You treat it as safe in strncmp, but then you call a function (strchr) that 'requires/checks' it to be safe, implying you weren't sure." --- src/command/cmd_ac.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index a632ceae..19785399 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1545,6 +1545,10 @@ cmd_ac_remove_form_fields(DataForm* form) char* cmd_ac_complete(ProfWin* window, const char* const input, gboolean previous) { + if (!input) { + return NULL; + } + char* found = NULL; // autocomplete command if ((strncmp(input, "/", 1) == 0) && (!strchr(input, ' '))) {