Merge branch 'michal/fix-cppcheck-2.2-issues' into 'main'

Fix cppcheck 2.2 issues

See merge request isc-projects/bind9!4292
This commit is contained in:
Michał Kępień 2020-11-25 12:16:53 +00:00
commit aa3b489216
6 changed files with 38 additions and 32 deletions

View file

@ -422,9 +422,6 @@ 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')

View 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) {

View 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) {

View 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);

View file

@ -1217,11 +1217,6 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) {
"search for response in bucket %d: %s", bucket,
(resp == NULL ? "not found" : "found"));
if (resp == NULL) {
inc_stats(mgr, dns_resstatscounter_mismatch);
free_buffer(disp, ev->region.base, ev->region.length);
goto unlock;
}
} else if (resp->id != id ||
!isc_sockaddr_equal(&ev->address, &resp->host)) {
dispatch_log(disp, LVL(90),
@ -1231,6 +1226,12 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) {
goto unlock;
}
if (resp == NULL) {
inc_stats(mgr, dns_resstatscounter_mismatch);
free_buffer(disp, ev->region.base, ev->region.length);
goto unlock;
}
/*
* Now that we have the original dispatch the query was sent
* from check that the address and port the response was

View file

@ -52,19 +52,29 @@ isc_quota_get_set_test(void **state) {
isc_quota_destroy(&quota);
}
#define add_quota(quota, quotasp, exp, attached, exp_used) \
{ \
*quotasp = NULL; \
isc_result_t result = isc_quota_attach(quota, quotasp); \
assert_int_equal(result, exp); \
if (attached) { \
assert_ptr_equal(*quotasp, quota); \
} else { \
assert_null(*quotasp); \
} \
assert_int_equal(isc_quota_getused(quota), exp_used); \
static void
add_quota(isc_quota_t *source, isc_quota_t **target,
isc_result_t expected_result, int expected_used) {
isc_result_t result;
*target = NULL;
result = isc_quota_attach(source, target);
assert_int_equal(result, expected_result);
switch (expected_result) {
case ISC_R_SUCCESS:
case ISC_R_SOFTQUOTA:
assert_ptr_equal(*target, source);
break;
default:
assert_null(*target);
break;
}
assert_int_equal(isc_quota_getused(source), expected_used);
}
static void
isc_quota_hard_test(void **state) {
isc_quota_t quota;
@ -75,18 +85,18 @@ isc_quota_hard_test(void **state) {
isc_quota_init(&quota, 100);
for (i = 0; i < 100; i++) {
add_quota(&quota, &quotas[i], ISC_R_SUCCESS, true, i + 1);
add_quota(&quota, &quotas[i], ISC_R_SUCCESS, i + 1);
}
add_quota(&quota, &quotas[100], ISC_R_QUOTA, false, 100);
add_quota(&quota, &quotas[100], ISC_R_QUOTA, 100);
assert_int_equal(isc_quota_getused(&quota), 100);
isc_quota_detach(&quotas[0]);
assert_null(quotas[0]);
add_quota(&quota, &quotas[100], ISC_R_SUCCESS, true, 100);
add_quota(&quota, &quotas[101], ISC_R_QUOTA, false, 100);
add_quota(&quota, &quotas[100], ISC_R_SUCCESS, 100);
add_quota(&quota, &quotas[101], ISC_R_QUOTA, 100);
for (i = 100; i > 0; i--) {
isc_quota_detach(&quotas[i]);
@ -108,13 +118,13 @@ isc_quota_soft_test(void **state) {
isc_quota_soft(&quota, 50);
for (i = 0; i < 50; i++) {
add_quota(&quota, &quotas[i], ISC_R_SUCCESS, true, i + 1);
add_quota(&quota, &quotas[i], ISC_R_SUCCESS, i + 1);
}
for (i = 50; i < 100; i++) {
add_quota(&quota, &quotas[i], ISC_R_SOFTQUOTA, true, i + 1);
add_quota(&quota, &quotas[i], ISC_R_SOFTQUOTA, i + 1);
}
add_quota(&quota, &quotas[i], ISC_R_QUOTA, false, 100);
add_quota(&quota, &quotas[i], ISC_R_QUOTA, 100);
for (i = 99; i >= 0; i--) {
isc_quota_detach(&quotas[i]);