]> The Tcpdump Group git mirrors - libpcap/commitdiff
Make it clearer where we're testing whether a value is unknown.
authorGuy Harris <[email protected]>
Mon, 18 Sep 2017 01:07:58 +0000 (18:07 -0700)
committerGuy Harris <[email protected]>
Mon, 18 Sep 2017 01:07:58 +0000 (18:07 -0700)
Add a #define of VAL_UNKNOWN for 0, and compare val[i] values against
that.

gencode.h
optimize.c

index 70fe37ea38551f2dffe914fc47430128a65ae201..58828ecd5854b3f43eb28b4fed251a83278e0f33 100644 (file)
--- a/gencode.h
+++ b/gencode.h
@@ -266,6 +266,11 @@ struct block {
        int val[N_ATOMS];
 };
 
+/*
+ * A value of 0 for val[i] means the value is unknown.
+ */
+#define VAL_UNKNOWN    0
+
 struct arth {
        struct block *b;        /* protocol checks */
        struct slist *s;        /* stmt list */
index 0bf52cdd8f4f2c72c077f309b8474cf588b6ec77..4beb90f88085b33c7d84803d1f72d35c111487d4 100644 (file)
@@ -578,7 +578,7 @@ F(opt_state_t *opt_state, int code, int v0, int v1)
 static inline void
 vstore(struct stmt *s, int *valp, int newval, int alter)
 {
-       if (alter && newval != 0 && *valp == newval)
+       if (alter && newval != VAL_UNKNOWN && *valp == newval)
                s->code = NOP;
        else
                *valp = newval;
@@ -1242,8 +1242,9 @@ opt_blk(compiler_state_t *cstate, struct icode *ic, opt_state_t *opt_state,
         * block, can we eliminate it?
         */
        if (do_stmts &&
-           ((b->out_use == 0 && aval != 0 && b->val[A_ATOM] == aval &&
-             xval != 0 && b->val[X_ATOM] == xval) ||
+           ((b->out_use == 0 &&
+             aval != VAL_UNKNOWN && b->val[A_ATOM] == aval &&
+             xval != VAL_UNKNOWN && b->val[X_ATOM] == xval) ||
             BPF_CLASS(b->s.code) == BPF_RET)) {
                if (b->stmts != 0) {
                        b->stmts = 0;
@@ -2275,7 +2276,7 @@ dot_dump_node(struct icode *ic, struct block *block, struct bpf_program *prog,
        }
        fprintf(out, "\" tooltip=\"");
        for (i = 0; i < BPF_MEMWORDS; i++)
-               if (block->val[i] != 0)
+               if (block->val[i] != VAL_UNKNOWN)
                        fprintf(out, "val[%d]=%d ", i, block->val[i]);
        fprintf(out, "val[A]=%d ", block->val[A_ATOM]);
        fprintf(out, "val[X]=%d", block->val[X_ATOM]);