From 8ca93c983b95e607317357da8cd62b2f3fc3457d Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 5 Jan 2024 03:32:05 -0800 Subject: [PATCH] gtk.cfg: Add more definitions for assert macros (#5830) In particular, the missing definition of `g_assert_nonnull()` can cause false positives because it's not recognized as `assert(expr != NULL)` by cppcheck. --- cfg/gtk.cfg | 3 +++ test/cfg/gtk.c | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 6b3f13547..20869faf8 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -178,11 +178,14 @@ + + + diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index 4557173b9..2644f95f0 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -2,7 +2,7 @@ // Test library configuration for gtk.cfg // // Usage: -// $ cppcheck --check-library --library=gtk --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr --library=gtk test/cfg/gtk.cpp +// $ cppcheck --check-library --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr --library=gtk test/cfg/gtk.c // => // No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 // @@ -230,6 +230,25 @@ void g_assert_test() g_assert(a = 5); } +void g_assert_true_false_test() +{ + gboolean t = TRUE; + gboolean f = FALSE; + g_assert_true(t); + // cppcheck-suppress checkLibraryNoReturn + g_assert_false(f); +} + +void g_assert_null_nonnull_test() +{ + char * gpt = g_malloc(1); + g_assert_nonnull(gpt); + gpt[0] = 0; + g_free(gpt); + // cppcheck-suppress checkLibraryNoReturn + g_assert_null(NULL); +} + void g_print_test() { // cppcheck-suppress invalidPrintfArgType_uint