]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
cppcheck: Address cpcheck report of an FP
authorJeff Lucovsky <jlucovsky@oisf.net>
Sat, 25 Nov 2023 14:22:19 +0000 (09:22 -0500)
committerVictor Julien <victor@inliniac.net>
Thu, 29 Feb 2024 10:24:41 +0000 (11:24 +0100)
Issue: 6527

Address the FP raised by cppcheck -- note that although the code
corectly checks to ensure that `to_shift != &sb->reqion`, the logic was
detected as a FP. Rework the code to eliminate the FP.

(cherry picked from commit 40e3514e7a6c89a786ebf17469404524fb0d2d52)

src/util-streaming-buffer.c

index 7608b5082109caa68e6b6161a8e703c44d232192..6ff4f438a40a5d68aac064c55f0836ff3773831d 100644 (file)
@@ -842,16 +842,11 @@ static inline void StreamingBufferSlideToOffsetWithRegions(
             r = next;
         }
         SCLogDebug("to_shift %p", to_shift);
-    } else {
-        to_shift = &sb->region;
-        SCLogDebug("shift start region %p", to_shift);
-    }
 
-    // this region is main, or will xfer its buffer to main
-    if (to_shift) {
-        SCLogDebug("main: offset %" PRIu64 " buf %p size %u offset %u", to_shift->stream_offset,
-                to_shift->buf, to_shift->buf_size, to_shift->buf_offset);
-        if (to_shift != &sb->region) {
+        // this region is main, or will xfer its buffer to main
+        if (to_shift && to_shift != &sb->region) {
+            SCLogDebug("main: offset %" PRIu64 " buf %p size %u offset %u", to_shift->stream_offset,
+                    to_shift->buf, to_shift->buf_size, to_shift->buf_offset);
             DEBUG_VALIDATE_BUG_ON(sb->region.buf != NULL);
 
             sb->region.buf = to_shift->buf;
@@ -860,12 +855,20 @@ static inline void StreamingBufferSlideToOffsetWithRegions(
             sb->region.buf_size = to_shift->buf_size;
             sb->region.next = to_shift->next;
 
+            BUG_ON(to_shift == &sb->region);
             FREE(cfg, to_shift, sizeof(*to_shift));
             to_shift = &sb->region;
             sb->regions--;
             DEBUG_VALIDATE_BUG_ON(sb->regions == 0);
         }
 
+    } else {
+        to_shift = &sb->region;
+        SCLogDebug("shift start region %p", to_shift);
+    }
+
+    // this region is main, or will xfer its buffer to main
+    if (to_shift) {
         // Do the shift. If new region is exactly at the slide offset we can skip this.
         DEBUG_VALIDATE_BUG_ON(to_shift->stream_offset > slide_offset);
         const uint32_t s = slide_offset - to_shift->stream_offset;