Skip to contentSkip to conversation

evaluate: zap useless 0-shifts

PATCH In review Florian Westphal 2 participants 2 messages Apr 22 – Apr 23 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 evaluate: zap useless 0-shifts

There is a (not yet applied) kernel patch that rejects 0-shifts, auto-suppress them at eval stage.

---
 src/evaluate.c | 6 ++++++
 1 file changed, 6 insertions(+)
src/evaluate.c +6 -0
index 482708ae6191..8bb7b6095309 100644
@@ -1454,6 +1454,12 @@ static int expr_evaluate_shift(struct eval_ctx *ctx, struct expr **expr)
 					 "shifts exceeding %u bits are not supported", UINT_MAX);
 
 	shift = mpz_get_uint32(right->value);
+	if (shift == 0) {
+		*expr = expr_get(left);
+		expr_free(op);
+		return 0;
+	}
+
 	if (ctx->stmt_len > left->len)
 		max_shift_len = ctx->stmt_len;
 	else
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Florian Westphal

There is a (not yet applied) kernel patch that rejects 0-shifts, auto-suppress them at eval stage.

---

That is quite elegant indeed, thanks!

Quoted 20 lines
  src/evaluate.c | 6 ++++++
  1 file changed, 6 insertions(+)
src/evaluate.c +6 -0
index 482708ae6191..8bb7b6095309 100644
@@ -1454,6 +1454,12 @@ static int expr_evaluate_shift(struct eval_ctx *ctx, struct expr **expr)
  					 "shifts exceeding %u bits are not supported", UINT_MAX);
 
  	shift = mpz_get_uint32(right->value);
+	if (shift == 0) {
+		*expr = expr_get(left);
+		expr_free(op);
+		return 0;
+	}
+
  	if (ctx->stmt_len > left->len)
  		max_shift_len = ctx->stmt_len;
  	else