]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3369: SfIp: Follow up for warning suppression
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 12 Apr 2022 16:43:53 +0000 (16:43 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 12 Apr 2022 16:43:53 +0000 (16:43 +0000)
Merge in SNORT/snort3 from ~ASERBENI/snort3:sfip_warn_suppress to master

Squashed commit of the following:

commit f036849106353c02ceabf795e655cb298664a4fb
Author: Andrii Serbeniuk <aserbeni@cisco.com>
Date:   Thu Apr 7 13:49:28 2022 +0300

    sfip: improve warning suppression

src/sfip/sf_ip.cc
src/sfip/sf_ip.h
src/utils/cpp_macros.h

index ae7802bba04ea4a5ae4d8831441e6adc5f8963c6..04c960cbf320ff2be4f75cdf6eaa9c67c0f7785d 100644 (file)
@@ -42,11 +42,8 @@ bool SfIp::test_features{ false };
 /* Masks off 'val' bits from the IP contained within 'ip' */
 inline int SfIp::cidr_mask(int val)
 {
-    uint32_t* p;
     int index, bits;
 
-    p = ip32;
-
     if (val < 0 || val > 128)
         return SFIP_ARG_ERR;
 
@@ -64,14 +61,14 @@ inline int SfIp::cidr_mask(int val)
         mask = ~0;
         mask >>= bits;
         mask <<= bits;
-        p[index] &= htonl(mask);
+        ip32[index] &= htonl(mask);
     }
 
     index++;
 
     /* 0 off the rest of the IP */
     for (; index < 4; index++)
-        p[index] = 0;
+        ip32[index] = 0;
 
     return SFIP_SUCCESS;
 }
index 7a2aed2a83eb5d49ea354ea4b6c2208b5d2cc2bb..19e9fac9624a9aeaeba7390515e068bbe54d4cf8 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "main/snort_types.h"
 #include "sfip/sf_returns.h"
+#include "utils/cpp_macros.h"
 
 namespace snort
 {
@@ -145,8 +146,7 @@ inline uint32_t SfIp::get_ip4_value() const
 }
 
 /* Safe to ignore because ip32 is at the offset of 0 in SfIp */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+PACKED_MEMBER_ADDR_BEGIN
 
 inline const uint32_t* SfIp::get_ip4_ptr() const
 {
@@ -165,7 +165,7 @@ inline const uint32_t* SfIp::get_ptr() const
     return ip32;
 }
 
-#pragma GCC diagnostic pop
+PACKED_MEMBER_ADDR_END
 
 inline bool SfIp::is_set() const
 {
index 7d723bb99f710dd9897f87db60c7c5c72cc58e0f..f77314a550b560c491e2ccdae4101a7625327294 100644 (file)
 #  define PADDING_GUARD_END
 #endif
 
+// Pair of macros to temporarily disable and then enable warnings for code
+// that is accessing members of packed types with pointers
+#if defined(__clang__) && __clang_major__ >= 4 && !defined(__ICC)
+#  define PACKED_MEMBER_ADDR_BEGIN \
+    _Pragma(STRINGIFY( clang diagnostic push )) \
+    _Pragma(STRINGIFY( clang diagnostic ignored "-Waddress-of-packed-member" ))
+#  define PACKED_MEMBER_ADDR_END \
+    _Pragma(STRINGIFY( clang diagnostic pop ))
+#elif defined(__GNUC__) && __GNUC__ >= 9 && !defined(__ICC)
+#  define PACKED_MEMBER_ADDR_BEGIN \
+    _Pragma(STRINGIFY( GCC diagnostic push )) \
+    _Pragma(STRINGIFY( GCC diagnostic ignored "-Waddress-of-packed-member" ))
+#  define PACKED_MEMBER_ADDR_END \
+    _Pragma(STRINGIFY( GCC diagnostic pop ))
+#else
+#  define PACKED_MEMBER_ADDR_BEGIN
+#  define PACKED_MEMBER_ADDR_END
+#endif
+
 #endif