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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/datatype.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

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);
-- 
2.35.1




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux