]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Work around cppcheck 2.0 uninitvar false positives
authorMichał Kępień <michal@isc.org>
Mon, 18 May 2020 08:23:06 +0000 (10:23 +0200)
committerMichał Kępień <michal@isc.org>
Mon, 18 May 2020 08:41:41 +0000 (10:41 +0200)
cppcheck 2.0 reports false positives about uninitialized variables in a
lot of places throughout BIND source code, e.g.:

    bin/dig/host.c:386:24: error: Uninitialized variable: length [uninitvar]
     printf("%.*s", (int)r.length, (char *)r.base);
                           ^

Apparently cppcheck 2.0 has issues with processing (&var)->field syntax,
which is what the macros from lib/isc/include/isc/buffer.h are evaluated
to.  This issue was reported upstream [1] and will hopefully be
addressed in a future cppcheck release.

In the meantime, to avoid modifying BIND source code in multiple places
just because of a static checker false positive, work around the issue
by adding intermediate variables to buffer macro definitions using a sed
invocation in the cppcheck job script.

[1] https://sourceforge.net/p/cppcheck/discussion/general/thread/122153e3c1/

(cherry picked from commit 481fa34e50a6183273f71175adf93bfb12cad1e9)

.gitlab-ci.yml

index bc2bca82d64a1eb15165d0b4605f2eb645150363..0b9116945da1a2cb8cebe929c7844dd94665f48d 100644 (file)
@@ -352,6 +352,9 @@ stages:
   <<: *default_triggering_rules
   stage: postcheck
   script:
+    # Workaround for cppcheck 2.0 uninitvar false positives triggered by (&var)->field syntax
+    # (see: https://sourceforge.net/p/cppcheck/discussion/general/thread/122153e3c1/)
+    - sed -i '/^#define ISC__BUFFER.*\\$/{s|_b|__b|;N;s|do {|\0 isc_buffer_t *_b = (isc_buffer_t *)__b;|}; /^#define ISC__BUFFER.*REGION.*\\$/{s|_r|__r|;N;s|do {|\0 isc_region_t *_r = (isc_region_t *)__r;|; /USEDREGION/{s|isc_buffer_t|const \0|g}}' lib/isc/include/isc/buffer.h
     - *configure
     - (make -nwk all || true) | compiledb
     - export GCC_VERSION=$(gcc --version | sed -n 's/.* \([0-9]\+\)\.[0-9]\+\.[0-9]\+.*/\1/p')