Skip to contentSkip to conversation

src: fix always-true assertions

PATCH In review Florian Westphal 2 participants 3 messages Apr 26, 2022 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 src: fix always-true assertions

assert(1) is a no-op, this should be assert(0). Use BUG() instead. Add missing CATCHALL to avoid BUG().

---
 src/evaluate.c  | 2 +-
 src/intervals.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
src/evaluate.c +1 -1
index b5f74d2f5051..1447a4c28aee 100644
@@ -1499,7 +1499,7 @@ static int interval_set_eval(struct eval_ctx *ctx, struct set *set,
 	case CMD_GET:
 		break;
 	default:
-		assert(1);
+		BUG("unhandled op %d\n", ctx->cmd->op);
 		break;
 	}
 
src/intervals.c +3 -2
index a74238525d8d..85ec59eda36a 100644
@@ -20,6 +20,7 @@ static void setelem_expr_to_range(struct expr *expr)
 	assert(expr->etype == EXPR_SET_ELEM);
 
 	switch (expr->key->etype) {
+	case EXPR_SET_ELEM_CATCHALL:
 	case EXPR_RANGE:
 		break;
 	case EXPR_PREFIX:
@@ -53,7 +54,7 @@ static void setelem_expr_to_range(struct expr *expr)
 		expr->key = key;
 		break;
 	default:
-		assert(1);
+		BUG("unhandled key type %d\n", expr->key->etype);
 	}
 }
 
@@ -185,7 +186,7 @@ static struct expr *interval_expr_key(struct expr *i)
 		elem = i;
 		break;
 	default:
-		assert(1);
+		BUG("unhandled expression type %d\n", i->etype);
 		return NULL;
 	}
 
Signature · 1 line
2.35.1
#1 lore raw
Quoted 2 lines · Florian Westphal

assert(1) is a no-op, this should be assert(0). Use BUG() instead. Add missing CATCHALL to avoid BUG().

LGTM.

So this is fixing a bug with catch-all element, correct?

Quoted 52 lines
---
 src/evaluate.c  | 2 +-
 src/intervals.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
src/evaluate.c +1 -1
index b5f74d2f5051..1447a4c28aee 100644
@@ -1499,7 +1499,7 @@ static int interval_set_eval(struct eval_ctx *ctx, struct set *set,
 	case CMD_GET:
 		break;
 	default:
-		assert(1);
+		BUG("unhandled op %d\n", ctx->cmd->op);
 		break;
 	}
 
src/intervals.c +3 -2
index a74238525d8d..85ec59eda36a 100644
@@ -20,6 +20,7 @@ static void setelem_expr_to_range(struct expr *expr)
 	assert(expr->etype == EXPR_SET_ELEM);
 
 	switch (expr->key->etype) {
+	case EXPR_SET_ELEM_CATCHALL:
 	case EXPR_RANGE:
 		break;
 	case EXPR_PREFIX:
@@ -53,7 +54,7 @@ static void setelem_expr_to_range(struct expr *expr)
 		expr->key = key;
 		break;
 	default:
-		assert(1);
+		BUG("unhandled key type %d\n", expr->key->etype);
 	}
 }
 
@@ -185,7 +186,7 @@ static struct expr *interval_expr_key(struct expr *i)
 		elem = i;
 		break;
 	default:
-		assert(1);
+		BUG("unhandled expression type %d\n", i->etype);
 		return NULL;
 	}
 
Signature · 1 line
2.35.1
author maintainer
#2 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 2 lines · Florian Westphal

assert(1) is a no-op, this should be assert(0). Use BUG() instead. Add missing CATCHALL to avoid BUG().

LGTM.

So this is fixing a bug with catch-all element, correct?

Not really, the default label is hit, assert(1) does not do anything. After making the assertion work we need to avoid the 'default' label.