]> The Tcpdump Group git mirrors - libpcap/commitdiff
optimize: remove unnecessary tests.
authorGuy Harris <[email protected]>
Wed, 17 Jun 2020 20:28:39 +0000 (13:28 -0700)
committerGuy Harris <[email protected]>
Wed, 17 Jun 2020 20:28:39 +0000 (13:28 -0700)
We never insert more than 2 extra jumps in convert_code_r(); make the
count of extra jumps a u_char, so that no compiler doing insufficiently
careful data flow analysis thinks ZOMG IT CAN GET BIGGER THAN
256!!!!!!111ONEZ111!!!! and emits a bogus warning, and remove checks
whether it can get > 256.

This should address GitHub issue #944 without upsetting MSVC.

optimize.c

index 4fb7b0d29bc056c09d7e49950811034c4c8bbfd1..1336a98d4632531ae2d2885d298703d6396e49b9 100644 (file)
@@ -2688,7 +2688,7 @@ convert_code_r(conv_state_t *conv_state, struct icode *ic, struct block *p)
        struct slist *src;
        u_int slen;
        u_int off;
-       u_int extrajmps;        /* number of extra jumps inserted */
+       u_char extrajmps;       /* number of extra jumps inserted */
        struct slist **offset = NULL;
 
        if (p == 0 || isMarked(ic, p))
@@ -2821,12 +2821,7 @@ filled:
                        p->longjt++;
                        return(0);
                    }
-                   /* branch if T to following jump */
-                   if (extrajmps >= 256) {
-                       conv_error(conv_state, "too many extra jumps");
-                       /*NOTREACHED*/
-                   }
-                   dst->jt = (u_char)extrajmps;
+                   dst->jt = extrajmps;
                    extrajmps++;
                    dst[extrajmps].code = BPF_JMP|BPF_JA;
                    dst[extrajmps].k = off - extrajmps;
@@ -2843,11 +2838,7 @@ filled:
                    }
                    /* branch if F to following jump */
                    /* if two jumps are inserted, F goes to second one */
-                   if (extrajmps >= 256) {
-                       conv_error(conv_state, "too many extra jumps");
-                       /*NOTREACHED*/
-                   }
-                   dst->jf = (u_char)extrajmps;
+                   dst->jf = extrajmps;
                    extrajmps++;
                    dst[extrajmps].code = BPF_JMP|BPF_JA;
                    dst[extrajmps].k = off - extrajmps;