Skip to content

Commit f90fe3e

Browse files
committed
gtk.cfg: Add pure annotations for more GLib functions
This fixes assertWithSideEffect false positives for the following functions: g_error_matches g_list_find g_str_has_prefix g_str_has_suffix
1 parent ac061da commit f90fe3e

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

cfg/gtk.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,7 @@
22512251
</function>
22522252
<!-- GList * g_list_find (GList *list, gconstpointer data); -->
22532253
<function name="g_list_find">
2254+
<pure/>
22542255
<leak-ignore/>
22552256
<noreturn>false</noreturn>
22562257
<returnValue type="GList"/>
@@ -5218,6 +5219,7 @@
52185219
<!-- gboolean g_str_has_prefix (const gchar* str, const gchar* prefix); -->
52195220
<!-- gboolean g_str_has_suffix (const gchar* str, const gchar* prefix); -->
52205221
<function name="g_str_has_prefix,g_str_has_suffix">
5222+
<pure/>
52215223
<leak-ignore/>
52225224
<noreturn>false</noreturn>
52235225
<returnValue type="gboolean"/>
@@ -6586,6 +6588,7 @@
65866588
</function>
65876589
<!-- gboolean g_error_matches(const GError *error, GQuark domain, gint code); -->
65886590
<function name="g_error_matches">
6591+
<pure/>
65896592
<noreturn>false</noreturn>
65906593
<returnValue type="gboolean"/>
65916594
<use-retval/>

test/cfg/gtk.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void validCode(int argInt, GHashTableIter * hash_table_iter, GHashTable * hash_t
5959
g_string_free(pGStr1, TRUE);
6060

6161
gchar * pGchar1 = g_strconcat("a", "b", NULL);
62+
g_assert_true(g_str_has_prefix(pGchar1, "a"));
63+
g_assert_true(g_str_has_suffix(pGchar1, "b"));
6264
printf("%s", pGchar1);
6365
g_free(pGchar1);
6466

@@ -406,6 +408,7 @@ void g_error_new_test()
406408
g_error_new(1, -2, "a %d", 1);
407409

408410
const GError * pNew2 = g_error_new(1, -2, "a %d", 1);
411+
g_assert_true(g_error_matches(pNew2, 1, -2));
409412
printf("%p", pNew2);
410413
// cppcheck-suppress memleak
411414
}
@@ -530,6 +533,16 @@ void g_variant_test() {
530533
// cppcheck-suppress memleak
531534
}
532535

536+
void g_list_test() {
537+
GList *list1 = NULL;
538+
gchar *c = "c";
539+
540+
list1 = g_list_append(list1, c);
541+
g_assert_true(g_list_find(list1, c) != NULL);
542+
543+
g_list_free(list1);
544+
}
545+
533546
void g_queue_test() {
534547
// cppcheck-suppress leakReturnValNotUsed
535548
g_queue_new();

0 commit comments

Comments
 (0)