aboutsummaryrefslogtreecommitdiff
path: root/optimize.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-07-25 16:05:27 -0700
committerGuy Harris <guy@alum.mit.edu>2016-07-25 16:05:27 -0700
commit2d96be0322d71ce62e2f68d038070b10a7c9201b (patch)
tree140084663640fd718cb3bb1d01e649a23a883e4d /optimize.c
parent1a796886890fb989e2071d63d9d0279a046ec62c (diff)
Check for, and squelch, signed vs. unsigned comparison errors.
Use -Wsign-compare if the compiler supports it. If we're comparing an unsigned value with a signed value, and we've already determined that the signed value is >= 0, just cast it to an unsigned type. Use 0xffffffffU instead of -1 as the "unknown"/"unset"/etc. value for unsigned variables and fields. Assign the result of str2tok() to an int, not a u_int, as it can return -1. Declare some variables and fields unsigned if they don't need to be signed. Make sure some arguments passed into "set" functions are non-negative (and otherwise not invalid). In the BPF optimizer, cast the "constant" fields of a struct block to an unsigned type - the actual constant field of a BPF instruction is unsigned. Also, cast away one warning from MSVC.
Diffstat (limited to 'optimize.c')
-rw-r--r--optimize.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/optimize.c b/optimize.c
index d0a90683..baa9427c 100644
--- a/optimize.c
+++ b/optimize.c
@@ -885,7 +885,7 @@ opt_peep(opt_state_t *opt_state, struct block *b)
if (b->s.code == (BPF_JMP|BPF_K|BPF_JSET)) {
if (b->s.k == 0)
JT(b) = JF(b);
- if (b->s.k == 0xffffffff)
+ if ((u_int)b->s.k == 0xffffffffU)
JF(b) = JT(b);
}
/*
@@ -913,11 +913,11 @@ opt_peep(opt_state_t *opt_state, struct block *b)
break;
case BPF_JGT:
- v = (unsigned)v > b->s.k;
+ v = (unsigned)v > (unsigned)b->s.k;
break;
case BPF_JGE:
- v = (unsigned)v >= b->s.k;
+ v = (unsigned)v >= (unsigned)b->s.k;
break;
case BPF_JSET:
@@ -2046,7 +2046,7 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state,
dst = conv_state->ftail -= (slen + 1 + p->longjt + p->longjf);
/* inflate length by any extra jumps */
- p->offset = dst - conv_state->fstart;
+ p->offset = (int)(dst - conv_state->fstart);
/* generate offset[] for convenience */
if (slen) {