From 8f15ec46dcb2de49e57f5fbe1921e78a7d30b423 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 17 Apr 2024 19:39:56 +0100 Subject: [PATCH 1/2] Remove gcc warning when printf format is "" This warning only occurs when checking the msg_...() functions for having the correct parameters. The way I do that is by replacing the avrdude.h file with one that #defines the msg_... functions to printf for which the compiler knows which paramaters of which type are expected given that the format is a string constant. That check, however, produces false alarms which are not helpful. This commit switches these unhelpful warnings from gcc off. --- src/CMakeLists.txt | 2 +- src/configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82934f93..f9ddb59d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,7 +80,7 @@ if(MSVC) list(APPEND EXTRA_WINDOWS_INCLUDES "msvc") else() set(LIB_MATH m) - add_compile_options(-Wall -Wextra -Wno-unused-parameter) + add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-format-zero-length) endif() # ===================================== diff --git a/src/configure.ac b/src/configure.ac index 87647c8f..8b2d4ea3 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -556,7 +556,7 @@ fi # If we are compiling with gcc, enable all warnings and make warnings errors. ENABLE_WARNINGS="" if test "x$GCC" = xyes; then - ENABLE_WARNINGS="-Wall -Wextra -Wno-unused-parameter" + ENABLE_WARNINGS="-Wall -Wextra -Wno-unused-parameter -Wno-format-zero-length" # does this compiler support -Wno-pointer-sign ? AC_MSG_CHECKING([if gcc accepts -Wno-pointer-sign ]) From 5223750361e1cd1a613b060f3b90beb29b4642ed Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Thu, 18 Apr 2024 10:19:16 +0100 Subject: [PATCH 2/2] Inform gcc that avrdude_message2() has printf-like varargs --- src/avrdude.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/avrdude.h b/src/avrdude.h index c679a654..ad4055f7 100644 --- a/src/avrdude.h +++ b/src/avrdude.h @@ -45,7 +45,11 @@ extern const char *pgmid; // Programmer -c string #define mmt_malloc(n) cfg_malloc(__func__, n) #define mmt_realloc(p, n) cfg_realloc(__func__, p, n) -int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...); +int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...) +#if defined(__GNUC__) // Ask gcc to check whether format and parameters match + __attribute__ ((format (printf, 7, 8))) +#endif +; #define MSG_EXT_ERROR (-3) // OS-type error, no -v option, can be suppressed with -qqqqq #define MSG_ERROR (-2) // Avrdude error, no -v option, can be suppressed with -qqqq