]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
radix: add debug validation to assist scan-build
authorVictor Julien <vjulien@oisf.net>
Fri, 21 Apr 2023 12:57:22 +0000 (14:57 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Apr 2023 09:36:37 +0000 (11:36 +0200)
util-radix-tree.c:595:34: warning: Access to field 'stream' results in a dereference of a null pointer (loaded from field 'prefix') [core.NullDereference]
        if ((temp = (stream[i] ^ bottom_node->prefix->stream[i])) == 0) {
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
util-radix-tree.c:717:30: warning: Access to field 'stream' results in a dereference of a null pointer (loaded from field 'prefix') [core.NullDereference]
        if (SC_RADIX_BITTEST(bottom_node->prefix->stream[differ_bit >> 3],
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./util-radix-tree.h:27:34: note: expanded from macro 'SC_RADIX_BITTEST'
 #define SC_RADIX_BITTEST(x, y) ((x) & (y))
                                 ^
2 warnings generated.

(cherry picked from commit fa5acc17430adb69293d8a04c4dec9848a73ae1f)

src/util-radix-tree.c

index c004138ac093a4081783cb7496523be1f3265614..714cdbf4f62fddd777b4bf7c9c81d5d5e6e25480 100644 (file)
@@ -33,6 +33,7 @@
 #include "util-byte.h"
 #include "util-cidr.h"
 #include "util-print.h"
+#include "util-validate.h"
 
 /**
  * \brief Allocates and returns a new instance of SCRadixUserData.
@@ -591,6 +592,9 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
      * the prefix */
     bottom_node = node;
 
+    DEBUG_VALIDATE_BUG_ON(bottom_node == NULL);
+    DEBUG_VALIDATE_BUG_ON(bottom_node->prefix == NULL);
+
     /* get the first bit position where the ips differ */
     check_bit = (node->bit < bitlen)? node->bit: bitlen;
     for (i = 0; (i * 8) < check_bit; i++) {