]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/address: remove useless checks
authorVictor Julien <vjulien@oisf.net>
Tue, 26 Apr 2022 18:04:28 +0000 (20:04 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 27 Apr 2022 10:17:51 +0000 (12:17 +0200)
Cppcheck flagged this:

src/detect-engine-address.c:1035:48: warning: Either the condition 'ghn!=NULL' is redundant or there is possible null pointer dereference: gh. [nullPointerRedundantCheck]
    int r = DetectAddressIsCompleteIPSpaceIPv4(gh->ipv4_head);
                                               ^
src/detect-engine-address.c:1297:17: note: Assuming that condition 'ghn!=NULL' is not redundant
        if (ghn != NULL) {
                ^
src/detect-engine-address.c:1283:44: note: Calling function 'DetectAddressIsCompleteIPSpace', 1st argument 'ghn' value is 0
        if (DetectAddressIsCompleteIPSpace(ghn)) {
                                           ^
src/detect-engine-address.c:1035:48: note: Null pointer dereference
    int r = DetectAddressIsCompleteIPSpaceIPv4(gh->ipv4_head);
                                               ^

Cleanup code could only be reached with non-NULL pointers, so simplify checks.

Bug: #5291.

src/detect-engine-address.c

index 954ebff61d3b09ca26bccf3b42ea052ca4ae7837..1dc6bcfaca50fa78ba022d4f4ad6f792866fc360 100644 (file)
@@ -1290,14 +1290,10 @@ int DetectAddressTestConfVars(void)
             goto error;
         }
 
-        if (gh != NULL) {
-            DetectAddressHeadFree(gh);
-            gh = NULL;
-        }
-        if (ghn != NULL) {
-            DetectAddressHeadFree(ghn);
-            ghn = NULL;
-        }
+        DetectAddressHeadFree(gh);
+        gh = NULL;
+        DetectAddressHeadFree(ghn);
+        ghn = NULL;
     }
 
     return 0;