diff mbox series

[nft,v4,04/32] datatype: support `NULL` symbol-tables when printing constants

Message ID 20220404121410.188509-5-jeremy@azazel.net
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series Extend values assignable to packet marks and payload fields | expand

Commit Message

Jeremy Sowden April 4, 2022, 12:13 p.m. UTC
If the symbol-table passed to `symbol_constant_print` is `NULL`, fall
back to printing the expression's base-type.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 src/datatype.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/datatype.c b/src/datatype.c
index b2e667cef2c6..668823b6c7b1 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -185,7 +185,7 @@  void symbolic_constant_print(const struct symbol_table *tbl,
 			     struct output_ctx *octx)
 {
 	unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
-	const struct symbolic_constant *s;
+	const struct symbolic_constant *s = NULL;
 	uint64_t val = 0;
 
 	/* Export the data in the correct byteorder for comparison */
@@ -193,12 +193,14 @@  void symbolic_constant_print(const struct symbol_table *tbl,
 	mpz_export_data(constant_data_ptr(val, expr->len), expr->value,
 			expr->byteorder, len);
 
-	for (s = tbl->symbols; s->identifier != NULL; s++) {
-		if (val == s->value)
-			break;
-	}
+	if (tbl != NULL)
+		for (s = tbl->symbols; s->identifier != NULL; s++) {
+			if (val == s->value)
+				break;
+		}
 
-	if (s->identifier == NULL || nft_output_numeric_symbol(octx))
+	if (s == NULL || s->identifier == NULL ||
+	    nft_output_numeric_symbol(octx))
 		return expr_basetype(expr)->print(expr, octx);
 
 	nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);