diff --git a/src/helper/log.c b/src/helper/log.c index 2dada3540..7acb154c6 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -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); diff --git a/src/helper/log.h b/src/helper/log.h index 474d082ed..b8e3e339a 100644 --- a/src/helper/log.h +++ b/src/helper/log.h @@ -15,6 +15,7 @@ #define OPENOCD_HELPER_LOG_H #include +#include /* To achieve C99 printf compatibility in MinGW, gnu_printf should be * used for __attribute__((format( ... ))), with GCC v4.4 or later @@ -86,9 +87,9 @@ int log_add_callback(log_callback_fn fn, void *priv); int log_remove_callback(log_callback_fn fn, void *priv); char *alloc_vprintf(const char *fmt, va_list ap) - __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 0))); + __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 0))) __nonnull((1)); char *alloc_printf(const char *fmt, ...) - __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 2))); + __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 2))) __nonnull((1)); const char *find_nonprint_char(const char *buf, unsigned int buf_len);