This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=72c00cf6d914c2f230cf62e34c3e2bebc6a468a1

commit 72c00cf6d914c2f230cf62e34c3e2bebc6a468a1 (HEAD -> main)
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Sun Nov 5 00:43:48 2023 +0100

    test: Improve cppcheck coverage
    
    We needed to at least define __GNUC__ and __GNUC_MINOR__ macros,
    otherwise cppcheck could not see the code attributes. And to point
    to the include directories used in the code base to make the headers
    analyzable.
    
    We need to add a new bunch of suppressions, which we add inline for
    false positives, that we do not want to track per line or where we do
    not want to suppress on the entire file.
    
    This makes it possible finally, to remove a bunch of suppression for
    previous false positives due to lack of information for cppcheck.
---
 dselect/pkgsublist.cc     |  2 --
 lib/dpkg/nfmalloc.c       |  8 ++++++++
 lib/dpkg/pkg-hash.c       |  2 ++
 lib/dpkg/triglib.c        |  2 --
 src/main/archives.c       |  4 ++++
 t/cppcheck.t              | 11 +++++++----
 t/cppcheck/cppcheck.supp  | 37 +++++++++----------------------------
 utils/start-stop-daemon.c |  4 ++++
 8 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/dselect/pkgsublist.cc b/dselect/pkgsublist.cc
index d7875dc69..ccfc7f556 100644
--- a/dselect/pkgsublist.cc
+++ b/dselect/pkgsublist.cc
@@ -108,8 +108,6 @@ void packagelist::addunavailable(deppossi *possi) {
     internerr("deppossi from package %s has nullptr clientdata's uprec",
               pkg_name(possi->up->up, pnaw_always));
 
-  // cppcheck-suppress[constVariable]: false positive, operator() modifies it.
-  // cppcheck-suppress[constVariableReference]: idem, new name for the same.
   varbuf& vb= possi->up->up->clientdata->relations;
   vb(possi->ed->name);
   vb(_(" does not appear to be available\n"));
diff --git a/lib/dpkg/nfmalloc.c b/lib/dpkg/nfmalloc.c
index c2eca62a2..ebe35b8bd 100644
--- a/lib/dpkg/nfmalloc.c
+++ b/lib/dpkg/nfmalloc.c
@@ -50,11 +50,15 @@ void *
 nfmalloc(size_t size)
 {
   OBSTACK_INIT;
+  /* cppcheck-suppress[nullPointerArithmetic]:
+   * False positive, imported module. */
   return obstack_alloc(&db_obs, size);
 }
 
 char *nfstrsave(const char *string) {
   OBSTACK_INIT;
+  /* cppcheck-suppress[nullPointerArithmetic]:
+   * False positive, imported module. */
   return obstack_copy0 (&db_obs, string, strlen(string));
 }
 
@@ -62,11 +66,15 @@ char *
 nfstrnsave(const char *string, size_t size)
 {
   OBSTACK_INIT;
+  /* cppcheck-suppress[nullPointerArithmetic]:
+   * False positive, imported module. */
   return obstack_copy0(&db_obs, string, size);
 }
 
 void nffreeall(void) {
   if (dbobs_init) {
+    /* cppcheck-suppress[nullPointerArithmetic,pointerLessThanZero]:
+     * False positive, imported module. */
     obstack_free(&db_obs, NULL);
     dbobs_init = false;
   }
diff --git a/lib/dpkg/pkg-hash.c b/lib/dpkg/pkg-hash.c
index 6b0d33768..b6bc126ad 100644
--- a/lib/dpkg/pkg-hash.c
+++ b/lib/dpkg/pkg-hash.c
@@ -194,6 +194,8 @@ pkg_hash_get_pkg(struct pkgset *set, const struct dpkg_arch 
*arch)
   /* Match the slot with the most appropriate architecture. The installed
    * architecture always has preference over the available one, as there's
    * a small time window on cross-grades, where they might differ. */
+  /* cppcheck-suppress[knownConditionTrueFalse,knownPointerToBool]:
+   * False positive, the condition always ends up being false. */
   for (pkgp = &pkg; *pkgp; pkgp = &(*pkgp)->arch_next) {
     if ((*pkgp)->installed.arch == arch)
       return *pkgp;
diff --git a/lib/dpkg/triglib.c b/lib/dpkg/triglib.c
index c94f1be33..82cb2989b 100644
--- a/lib/dpkg/triglib.c
+++ b/lib/dpkg/triglib.c
@@ -411,8 +411,6 @@ static const struct trigkindinfo tki_explicit = {
 /*---------- File triggers. ----------*/
 
 static struct {
-       /* cppcheck-suppress[unusedStructMember]:
-        * False positive, macros from dlist.h use the tail member. */
        struct trigfileint *head, *tail;
 } filetriggers;
 
diff --git a/src/main/archives.c b/src/main/archives.c
index d91cb81b8..13263d2db 100644
--- a/src/main/archives.c
+++ b/src/main/archives.c
@@ -89,6 +89,8 @@ tar_pool_alloc(size_t size)
     tar_pool_init = true;
   }
 
+  /* cppcheck-suppress[nullPointerArithmetic]:
+   * False positive, imported module. */
   return obstack_alloc(&tar_pool, size);
 }
 
@@ -108,6 +110,8 @@ static void
 tar_pool_release(void)
 {
   if (tar_pool_init) {
+    /* cppcheck-suppress[nullPointerArithmetic,pointerLessThanZero]:
+     * False positive, imported module. */
     obstack_free(&tar_pool, NULL);
     tar_pool_init = false;
   }
diff --git a/t/cppcheck.t b/t/cppcheck.t
index 3f48389ef..1ee7e84ed 100644
--- a/t/cppcheck.t
+++ b/t/cppcheck.t
@@ -25,10 +25,6 @@ test_needs_srcdir_switch();
 
 plan tests => 1;
 
-# XXX: We should add the following to @cppcheck_opts, but then cppcheck emits
-# tons of false positives due to not understanding non-returning functions.
-#  -DLIBDPKG_VOLATILE_API=1
-#  -Ilib
 my @cppcheck_opts = (qw(
   --quiet
   --force
@@ -36,8 +32,15 @@ my @cppcheck_opts = (qw(
   --inline-suppr
   --suppressions-list=t/cppcheck/cppcheck.supp
   --std=c99 --std=c++03
+  -Ilib
+  -Ilib/compat
+  -Isrc/common
+  -I.
+  -D__GNUC__=12
+  -D__GNUC_MINOR__=0
   -D_DIRENT_HAVE_D_TYPE=1
   -DWITH_LIBSELINUX=1
+  -DLIBDPKG_VOLATILE_API=1
 ), (
   '--enable=warning,performance,portability,style',
   '--template=\'{file}:{line}: {severity} ({id}): {message}\''
diff --git a/t/cppcheck/cppcheck.supp b/t/cppcheck/cppcheck.supp
index 0b48e1cae..ed183fd55 100644
--- a/t/cppcheck/cppcheck.supp
+++ b/t/cppcheck/cppcheck.supp
@@ -5,11 +5,15 @@
 // We assume that the system has a sane NULL definition.
 varFuncNullUB
 
+// We do not always want to make variables pointers to const.
+constVariablePointer
+
 // TODO: While perhaps valid there are many to handle right away.
 constParameterCallback
 constParameterPointer
 
 // Ignore, this is an imported module.
+cstyleCast:lib/compat/gettext.h
 unusedStructMember:lib/compat/obstack.c
 nullPointerArithmetic:lib/compat/obstack.c
 
@@ -17,32 +21,9 @@ nullPointerArithmetic:lib/compat/obstack.c
 uninitMemberVar:*/Dpkg_Shlibs/patterns.cpp
 unusedStructMember:*/Dpkg_Shlibs/patterns.cpp
 
-// Ignore, the code is testing the macros.
-knownConditionTrueFalse:lib/dpkg/t/t-macros.c
-
-// BUG: False positive, the condition always ends up being false.
-knownConditionTrueFalse:lib/dpkg/pkg-hash.c
-knownPointerToBool:lib/dpkg/pkg-hash.c
-
-// BUG: False positive, it gets triggered even with -Ilib.
-unknownMacro:lib/dpkg/string.h
-unknownMacro:utils/*.c
+// Ignore, the code is testing whether the functions return.
+unreachableCode:lib/dpkg/t/t-ehandle.c
 
-// BUG: False positive.
-syntaxError:lib/dpkg/t/*.c
-
-// BUG: False positive.
-AssignmentIntegerToAddress:dselect/pkgdepcon.cc
-AssignmentIntegerToAddress:dselect/pkgsublist.cc
-
-// BUG: False positive, does not understand non-returning functors.
-nullPointerArithmeticRedundantCheck:lib/dpkg/db-fsys-files.c
-nullPointerArithmeticRedundantCheck:lib/dpkg/db-fsys-override.c
-nullPointerRedundantCheck:lib/dpkg/db-fsys-override.c
-nullPointerRedundantCheck:lib/dpkg/ehandle.c
-nullPointerRedundantCheck:src/deb/build.c
-nullPointerRedundantCheck:src/main/enquiry.c
-nullPointerRedundantCheck:src/main/unpack.c
-
-// BUG: False positive, due to our local va_copy().
-va_list_usedBeforeStarted:lib/compat/vasprintf.c
+// Ignore, the code is testing the macros.
+duplicateExpression:lib/dpkg/t/t-macros.c
+duplicateValueTernary:lib/dpkg/t/t-macros.c
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 75c440cb2..203bbb674 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -365,6 +365,8 @@ fatal(const char *format, ...)
 
        va_start(args, format);
        fatalv(0, format, args);
+       /* cppcheck-suppress[va_end_missing]:
+        * False positive, fatalv() is non-returning. */
 }
 
 static void LIBCOMPAT_ATTR_NORET LIBCOMPAT_ATTR_PRINTF(1)
@@ -374,6 +376,8 @@ fatale(const char *format, ...)
 
        va_start(args, format);
        fatalv(errno, format, args);
+       /* cppcheck-suppress[va_end_missing]:
+        * False positive, fatalv() is non-returning. */
 }
 
 #define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__)

-- 
Dpkg.Org's dpkg

Reply via email to