Skip to content

Commit 395ef5e

Browse files
committed
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.
1 parent e5f9f00 commit 395ef5e

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎cfg/gtk.cfg‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,8 +3285,7 @@
32853285
<returnValue type="gchar*"/>
32863286
<arg nr="1" direction="out">
32873287
<not-null/>
3288-
<not-uninit/>
3289-
<strz/>
3288+
<minsize type="argvalue" arg="2"/>
32903289
</arg>
32913290
<arg nr="2" direction="in">
32923291
<not-bool/>
@@ -3299,10 +3298,6 @@
32993298
<strz/>
33003299
<formatstr/>
33013300
</arg>
3302-
<arg nr="4" direction="in">
3303-
<not-bool/>
3304-
<not-uninit/>
3305-
</arg>
33063301
</function>
33073302
<!-- gboolean g_ascii_isalnum(gchar c); -->
33083303
<function name="g_ascii_isalnum">

‎test/cfg/gtk.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,20 @@ int g_return_val_if_reached_test(const char *s) {
655655

656656
return 0;
657657
}
658+
659+
void g_ascii_formatd_test(double d)
660+
{
661+
// g_ascii_formatd() writes the buffer and formats exactly one double
662+
gchar buf[39];
663+
g_ascii_formatd(buf, sizeof(buf), "%.2f", d);
664+
g_print("%s", buf);
665+
666+
// cppcheck-suppress invalidPrintfArgType_sint
667+
g_ascii_formatd(buf, sizeof(buf), "%d", d);
668+
g_print("%s", buf);
669+
670+
gchar small[4];
671+
// cppcheck-suppress bufferAccessOutOfBounds
672+
g_ascii_formatd(small, sizeof(buf), "%.2f", d);
673+
g_print("%s", small);
674+
}

0 commit comments

Comments
 (0)