forked from auracaster/openocd
helper/log: mark 'fmt' argument of alloc_*printf() as not NULL
Even after commit e12ceddd5e ("helper/log: mark `fmt` argument
of `alloc_vprintf()` as format string"), the GCC compiler still
reports that alloc_vprintf() could call vsnprintf() with a NULL
format parameter.
Inform the compiler that alloc_vprintf() cannot accept NULL as
format string.
Add an assert() in alloc_vprintf() so even compilers that do not
use the function attribute 'nonnull' will play safe.
While there, extend the same fixes to alloc_printf() too.
Change-Id: Idfa4fe9c6dfb2acfbf434c392237937ae03f0e8a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Parshintsev Anatoly <anatoly.parshintsev@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9166
Tested-by: jenkins
Reviewed-by: Anatoly P <anatoly.parshintsev@syntacore.com>
This commit is contained in:
@@ -354,6 +354,8 @@ char *alloc_vprintf(const char *fmt, va_list ap)
|
||||
int len;
|
||||
char *string;
|
||||
|
||||
assert(fmt);
|
||||
|
||||
/* determine the length of the buffer needed */
|
||||
va_copy(ap_copy, ap);
|
||||
len = vsnprintf(NULL, 0, fmt, ap_copy);
|
||||
|
||||
Reference in New Issue
Block a user