From 395ef5e6f4dc696f8b43551b89396f03df91d30d Mon Sep 17 00:00:00 2001 From: Pieter Duchi Date: Wed, 21 Oct 2026 21:41:52 +0200 Subject: [PATCH 1/3] gtk.cfg: fix the g_ascii_formatd() configuration g_ascii_formatd(buffer, buf_len, format, d) formats exactly one double into buffer, but every call was reported as g_ascii_formatd format string requires 1 parameter but only 0 are given. Uninitialized variable: buffer - The double is a fixed argument: with it configured as arg 4 the format check did not count it. Leave it to the format string check, which now also checks its type. - buffer is written, not read: it need not be initialized or a string. Its size must be at least buf_len. --- cfg/gtk.cfg | 7 +------ test/cfg/gtk.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 3aee2e2b1a2..8fc40969855 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -3285,8 +3285,7 @@ - - + @@ -3299,10 +3298,6 @@ - - - - diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index b923135e2d9..0858a6b3554 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -655,3 +655,20 @@ int g_return_val_if_reached_test(const char *s) { return 0; } + +void g_ascii_formatd_test(double d) +{ + // g_ascii_formatd() writes the buffer and formats exactly one double + gchar buf[39]; + g_ascii_formatd(buf, sizeof(buf), "%.2f", d); + g_print("%s", buf); + + // cppcheck-suppress invalidPrintfArgType_sint + g_ascii_formatd(buf, sizeof(buf), "%d", d); + g_print("%s", buf); + + gchar small[4]; + // cppcheck-suppress bufferAccessOutOfBounds + g_ascii_formatd(small, sizeof(buf), "%.2f", d); + g_print("%s", small); +} From 65c0efeb53dfe83083cdc97a3c2993bd61e5a0b1 Mon Sep 17 00:00:00 2001 From: Pieter Duchi Date: Thu, 22 Oct 2026 08:27:29 +0200 Subject: [PATCH 2/3] gtk.cfg: keep reporting a bool as the g_ascii_formatd() value Review of the previous commit: dropping also dropped its , so with a format string that is not a literal a bool passed as the value was no longer reported (invalidFunctionArgBool). Describing arg 4 again makes the format check count it as a fixed argument and report "requires 1 parameter but only 0 are given" again, so describe it as the variadic argument instead, as gnu.cfg does. --- cfg/gtk.cfg | 3 +++ test/cfg/gtk.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 8fc40969855..e8e86043b4f 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -3298,6 +3298,9 @@ + + + diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index 0858a6b3554..f3e0f032b5e 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -672,3 +672,11 @@ void g_ascii_formatd_test(double d) g_ascii_formatd(small, sizeof(buf), "%.2f", d); g_print("%s", small); } + +void g_ascii_formatd_format_test(const gchar *format, int i) +{ + gchar buf[39]; + // cppcheck-suppress invalidFunctionArgBool + g_ascii_formatd(buf, sizeof(buf), format, i == 1); + g_print("%s", buf); +} From d9593a06954c4a932cf8b6c01f1a47792761dd70 Mon Sep 17 00:00:00 2001 From: Pieter Duchi Date: Thu, 22 Oct 2026 12:56:24 +0200 Subject: [PATCH 3/3] gtk.cfg: the g_ascii_formatd() value must be initialized Review of the previous commit: the variadic argument lacked the that gnu.cfg gives its variadic arguments, so an uninitialized struct member passed as the value was only reported as uninitvar, without uninitStructMember. --- cfg/gtk.cfg | 1 + test/cfg/gtk.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index e8e86043b4f..e7119755b3e 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -3300,6 +3300,7 @@ + diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index f3e0f032b5e..015aa6a6a3d 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -679,4 +679,11 @@ void g_ascii_formatd_format_test(const gchar *format, int i) // cppcheck-suppress invalidFunctionArgBool g_ascii_formatd(buf, sizeof(buf), format, i == 1); g_print("%s", buf); + + struct { + double x; + } s; + // cppcheck-suppress [uninitvar, uninitStructMember] + g_ascii_formatd(buf, sizeof(buf), format, s.x); + g_print("%s", buf); }