From cb6b8039478ffe14de9891897cd707b901f76bed Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 20 Aug 2025 14:43:35 +0200 Subject: [PATCH] helper: command: assert on command_print() with no command_invocation Commit 7f260f5009a7 ("helper/command: Handle Tcl return values consistently") allows calling command_print with the first parameter set to NULL. This should not be allowed. I cannot identify any part of OpenOCD that calls a command that in turn calls command_print() with NULL command_invocation. Adding __attribute__((nonnull (1, 2))) to the prototype of the functions does not trigger any positive with GCC and scan-build. Add an assert to detect such corner cases. This change is kept small and self contained to allow reverting it easily if a real use case is identified. Change-Id: I8aa6e5c0c341e818c0327eaa0d2bd5b6304c93b8 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/9091 Tested-by: jenkins --- src/helper/command.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 95b21f452..bf2c91814 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -348,13 +348,7 @@ void command_output_text(struct command_context *context, const char *data) static void command_vprint(struct command_invocation *cmd, va_list ap, const char *format, bool add_lf) { - /* - * FIXME: Why this check on !cmd ? - * Commit 7f260f5009a7 that introduces it, does not explain why! - * Was author not confident on the code change? - */ - if (!cmd) - return; + assert(cmd); // Quit on previous allocation error if (cmd->output == CMD_PRINT_OOM)