]> The Tcpdump Group git mirrors - tcpdump/commitdiff
netdissect.h: Update ND_TTEST2 to fix issue 443
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 27 Apr 2015 16:20:59 +0000 (18:20 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 27 Apr 2015 16:20:59 +0000 (18:20 +0200)
Add IS_NOT_NEGATIVE macro.
Avoid these warnings:
- comparison of unsigned expression >= 0 is always true [-Wtype-limits],
- comparison is always true due to limited range of data type [-Wtype-limits].

netdissect.h

index c377b62208048354088e38067c5893d49d1e59bb..9e369a994381fb332930eb9246d6b67139da4688 100644 (file)
@@ -270,8 +270,11 @@ struct netdissect_options {
  *
  *     http://www.kb.cert.org/vuls/id/162289
  */
+
+#define IS_NOT_NEGATIVE(x) (((x) > 0) || ((x) == 0))
+
 #define ND_TTEST2(var, l) \
-  ((l) >= 0 && \
+  (IS_NOT_NEGATIVE(l) && \
        ((uintptr_t)ndo->ndo_snapend - (l) <= (uintptr_t)ndo->ndo_snapend && \
          (uintptr_t)&(var) <= (uintptr_t)ndo->ndo_snapend - (l)))