Skip to content

Commit e1c1035

Browse files
authored
Fix #15138 gtk.cfg: fix the g_ascii_formatd() configuration (#8954)
1 parent 7df423c commit e1c1035

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎cfg/gtk.cfg‎

Lines changed: 2 additions & 3 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,7 +3298,7 @@
32993298
<strz/>
33003299
<formatstr/>
33013300
</arg>
3302-
<arg nr="4" direction="in">
3301+
<arg nr="variadic" direction="in">
33033302
<not-bool/>
33043303
<not-uninit/>
33053304
</arg>

‎test/cfg/gtk.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,35 @@ 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+
}
675+
676+
void g_ascii_formatd_format_test(const gchar *format, int i)
677+
{
678+
gchar buf[39];
679+
// cppcheck-suppress invalidFunctionArgBool
680+
g_ascii_formatd(buf, sizeof(buf), format, i == 1);
681+
g_print("%s", buf);
682+
683+
struct {
684+
double x;
685+
} s;
686+
// cppcheck-suppress [uninitvar, uninitStructMember]
687+
g_ascii_formatd(buf, sizeof(buf), format, s.x);
688+
g_print("%s", buf);
689+
}

0 commit comments

Comments
 (0)