This is an automated email from Gerrit.

"Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch 
set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8764

-- gerrit

commit 8e2ddaccdd8728a85f73f0c19e5b7aee08fe6933
Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>
Date:   Fri Feb 14 19:20:58 2025 +0300

    helper/log: mark `fmt` argument of `alloc_vprintf()` as non-null
    
    Building on Ubuntu 22.04 with `-fsanitize=undefined` (GCC 12.3.0)
    results in an error:
    ```
    In file included from /usr/include/stdio.h:894,
                     from /home/en-sc/openocd/src/helper/system.h:23,
                     from /home/en-sc/openocd/src/helper/replacements.h:18,
                     from /home/en-sc/openocd/src/helper/log.c:20:
    In function ‘vsnprintf’,
        inlined from ‘alloc_vprintf’ at 
/home/en-sc/openocd/src/helper/log.c:347:8:
    /usr/include/x86_64-linux-gnu/bits/stdio2.h:85:10: error: null format 
string [-Werror=format-truncation=]
       85 |   return __builtin___vsnprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 
1,
          |          
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       86 |                                     __glibc_objsize (__s), __fmt, 
__ap);
          |                                     
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    ```
    
    The error mentiones the call site `src/helper/log.c:347`. There
    `vsnprintf()` is called passing `fmt` as format string.
    
    Mark the format string as non-null in `alloc_vprintf()`.
    
    Change-Id: I91011490715998ef5a931c19c3c9d74a1a304e5d
    Signed-off-by: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>

diff --git a/src/helper/log.h b/src/helper/log.h
index e2bb131ed3..bf42166053 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -85,7 +85,7 @@ struct log_callback {
 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);
+char *alloc_vprintf(const char *fmt, va_list ap) __attribute__ ((nonnull (1)));
 char *alloc_printf(const char *fmt, ...)
        __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 2)));
 

-- 

Reply via email to