Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cfg/gtk.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5221,7 +5221,6 @@
<!-- gboolean g_str_has_prefix (const gchar* str, const gchar* prefix); -->
<!-- gboolean g_str_has_suffix (const gchar* str, const gchar* prefix); -->
<function name="g_str_has_prefix,g_str_has_suffix">
<pure/>
<leak-ignore/>
<noreturn>false</noreturn>
<returnValue type="gboolean"/>
Expand Down
6 changes: 6 additions & 0 deletions test/cfg/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ void validCode(int argInt, GHashTableIter * hash_table_iter, GHashTable * hash_t
g_string_free(pGStr1, TRUE);

gchar * pGchar1 = g_strconcat("a", "b", NULL);

// g_str_has_prefix and g_str_has_suffix can have side effects because they use
// g_return_val_if_fail, which logs to the console upon failure
// cppcheck-suppress assertWithSideEffect
g_assert_true(g_str_has_prefix(pGchar1, "a"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to keep this test case and suppress the warning to make the desired behavior more explicit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, that also allowed me to add a comment for future readers.

// cppcheck-suppress assertWithSideEffect
g_assert_true(g_str_has_suffix(pGchar1, "b"));

printf("%s", pGchar1);
g_free(pGchar1);

Expand Down
Loading