]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Ensure name count stays positive in remove_nodes()
authorOndřej Surý <ondrej@sury.org>
Tue, 5 Nov 2019 09:47:26 +0000 (10:47 +0100)
committerOndřej Surý <ondrej@sury.org>
Tue, 5 Nov 2019 22:07:07 +0000 (23:07 +0100)
This fixes a scan-build false-positive:

rbt_test.c:914:8: warning: Assigned value is garbage or undefined
                node %= *names_count;
                     ^  ~~~~~~~~~~~~
1 warning generated.

The remove_nodes() function is always called with correct arguments
(num_names is in <1;*names_count> range), so the modulo by zero cannot
happen, but nevertheless scan-build detects this and it's easy to fix.

lib/dns/tests/rbt_test.c

index ede9fec2359c70321455aeca6c9b0a8e561fb035..208a6ae54875fe5b2a62f5e0a64bf835341d12b6 100644 (file)
@@ -903,7 +903,7 @@ remove_nodes(dns_rbt_t *mytree, char **names,
 
        UNUSED(mytree);
 
-       for (i = 0; i < num_names; i++) {
+       for (i = 0; i < num_names && *names_count > 0; i++) {
                uint32_t node;
                dns_fixedname_t fname;
                dns_name_t *name;
@@ -920,11 +920,10 @@ remove_nodes(dns_rbt_t *mytree, char **names,
                assert_int_equal(result, ISC_R_SUCCESS);
 
                isc_mem_free(mctx, names[node]);
-               if (*names_count > 0) {
-                       names[node] = names[*names_count - 1];
-                       names[*names_count - 1] = NULL;
-                       *names_count -= 1;
-               }
+
+               names[node] = names[*names_count - 1];
+               names[*names_count - 1] = NULL;
+               *names_count -= 1;
        }
 }