helper: command: assert on command_print() with no command_invocation

Commit 7f260f5009 ("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 <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9091
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2025-08-20 14:43:35 +02:00
parent 1dedd6918b
commit cb6b803947

View File

@@ -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)