]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Teach cppcheck that fatal() does not return
authorMichał Kępień <michal@isc.org>
Wed, 25 Nov 2020 11:45:47 +0000 (12:45 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 25 Nov 2020 11:45:47 +0000 (12:45 +0100)
cppcheck is not aware that the bin/dnssec/dnssectool.c:fatal() function
does not return.  This triggers certain cppcheck 2.2 false positives,
for example:

    bin/dnssec/dnssec-signzone.c:3471:13: warning: Either the condition 'ndskeys==8' is redundant or the array 'dskeyfile[8]' is accessed at index 8, which is out of bounds. [arrayIndexOutOfBoundsCond]
       dskeyfile[ndskeys++] = isc_commandline_argument;
                ^
    bin/dnssec/dnssec-signzone.c:3468:16: note: Assuming that condition 'ndskeys==8' is not redundant
       if (ndskeys == MAXDSKEYS) {
                   ^
    bin/dnssec/dnssec-signzone.c:3471:13: note: Array index out of bounds
       dskeyfile[ndskeys++] = isc_commandline_argument;
                ^

    bin/dnssec/dnssec-signzone.c:772:20: warning: Either the condition 'l->hashbuf==NULL' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]
     memset(l->hashbuf + l->entries * l->length, 0, l->length);
                       ^
    bin/dnssec/dnssec-signzone.c:768:18: note: Assuming that condition 'l->hashbuf==NULL' is not redundant
      if (l->hashbuf == NULL) {
                     ^
    bin/dnssec/dnssec-signzone.c:772:20: note: Null pointer addition
     memset(l->hashbuf + l->entries * l->length, 0, l->length);
                       ^

Instead of suppressing all such warnings individually, conditionally
define a preprocessor macro which prevents them from being triggered.

bin/dnssec/dnssec-keyfromlabel.c
bin/dnssec/dnssec-keygen.c
bin/dnssec/dnssectool.h

index 81c6cc10377235cc9913c615696727a93b23ab2a..bb94c98a18de0e4129a6c6721360786934682bfa 100644 (file)
@@ -362,7 +362,6 @@ main(int argc, char **argv) {
        setup_logging(mctx, &log);
 
        if (predecessor == NULL) {
-               /* cppcheck-suppress nullPointerRedundantCheck */
                if (label == NULL) {
                        fatal("the key label was not specified");
                }
@@ -384,7 +383,6 @@ main(int argc, char **argv) {
                              isc_result_totext(ret));
                }
 
-               /* cppcheck-suppress nullPointerRedundantCheck */
                if (strchr(label, ':') == NULL) {
                        char *l;
                        int len;
@@ -396,13 +394,11 @@ main(int argc, char **argv) {
                        label = l;
                }
 
-               /* cppcheck-suppress nullPointerRedundantCheck */
                if (algname == NULL) {
                        fatal("no algorithm specified");
                }
 
                r.base = algname;
-               /* cppcheck-suppress nullPointerRedundantCheck */
                r.length = strlen(algname);
                ret = dns_secalg_fromtext(&alg, &r);
                if (ret != ISC_R_SUCCESS) {
index 30e16fb87f24f425b6370d5d839a75528b8750f1..f16d98257b878b02336e493dbac4f7d9f7415ac3 100644 (file)
@@ -1180,12 +1180,10 @@ main(int argc, char **argv) {
        }
 
        if (ctx.predecessor == NULL && ctx.policy == NULL) {
-               /* cppcheck-suppress nullPointerRedundantCheck */
                if (algname == NULL) {
                        fatal("no algorithm specified");
                }
                r.base = algname;
-               /* cppcheck-suppress nullPointerRedundantCheck */
                r.length = strlen(algname);
                ret = dns_secalg_fromtext(&ctx.alg, &r);
                if (ret != ISC_R_SUCCESS) {
index bb18c69183256af14e59c4e72c50ddf430c01655..e0970e2ae64bc513904f160291c68b2f0ff43cd5 100644 (file)
@@ -43,8 +43,12 @@ extern uint8_t dtype[8];
 
 typedef void(fatalcallback_t)(void);
 
+#ifndef CPPCHECK
 ISC_NORETURN void
 fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
+#else /* CPPCHECK */
+#define fatal(...) exit(1)
+#endif
 
 void
 setfatalcallback(fatalcallback_t *callback);