]> The Tcpdump Group git mirrors - tcpdump/commitdiff
ForCES: Fix undefined behaviour in op_valid().
authorDenis Ovsienko <[email protected]>
Tue, 5 Sep 2017 23:34:33 +0000 (00:34 +0100)
committerDenis Ovsienko <[email protected]>
Tue, 5 Sep 2017 23:52:57 +0000 (00:52 +0100)
[print-forces.c:316] -> [print-forces.c:323]: (warning) Shifting 32-bit
value by 32767 bits is undefined behaviour. See condition at line 323.
[print-forces.c:316]: (error) Shifting by a negative value is undefined
behaviour

print-forces.c

index a8f88c136a7bd90e73133043e92fa2e67b198879..702b8384621c37b4379cf68e0d69545dce703c52 100644 (file)
@@ -313,12 +313,10 @@ static inline char *indent_pr(int indent, int nlpref)
 
 static inline int op_valid(uint16_t op, uint16_t mask)
 {
-       int opb = 1 << (op - 1);
-
        if (op == 0)
                return 0;
-       if (opb & mask)
-               return 1;
+       if (op <= F_OP_MAX)
+               return (1 << (op - 1)) & mask; /* works only for 0x0001 through 0x0010 */
        /* I guess we should allow vendor operations? */
        if (op >= 0x8000)
                return 1;