From: Michał Kępień Date: Wed, 25 Nov 2020 11:45:47 +0000 (+0100) Subject: Teach cppcheck that fatal() does not return X-Git-Tag: v9.16.10~13^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e395ff54e51d13f60e3713ae7314a995a84af973;p=thirdparty%2Fbind9.git Teach cppcheck that fatal() does not return 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:3470: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:3467:16: note: Assuming that condition 'ndskeys==8' is not redundant if (ndskeys == MAXDSKEYS) { ^ bin/dnssec/dnssec-signzone.c:3470:13: note: Array index out of bounds dskeyfile[ndskeys++] = isc_commandline_argument; ^ bin/dnssec/dnssec-signzone.c:771: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:767:18: note: Assuming that condition 'l->hashbuf==NULL' is not redundant if (l->hashbuf == NULL) { ^ bin/dnssec/dnssec-signzone.c:771: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. (cherry picked from commit d9701e22b5b98fbc9915c319eb364a56652979bc) --- diff --git a/bin/dnssec/dnssectool.h b/bin/dnssec/dnssectool.h index 5f3c6ff3c61..be6907a727f 100644 --- a/bin/dnssec/dnssectool.h +++ b/bin/dnssec/dnssectool.h @@ -42,9 +42,13 @@ extern uint8_t dtype[8]; typedef void(fatalcallback_t)(void); +#ifndef CPPCHECK ISC_PLATFORM_NORETURN_PRE void fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST; +#else /* CPPCHECK */ +#define fatal(...) exit(1) +#endif void setfatalcallback(fatalcallback_t *callback);