evaluate: fix check for unknown in cmd_op_to_name
PATCH v2 1/1 evaluate: fix check for unknown in cmd_op_to_name
Example:
nft --debug=all destroy table ip missingtable
Before:
Evaluate unknown
After:
Evaluate destroy
Fixes e1dfd5cc4c46 ("src: add support to command "destroy"")
Signed-off-by 谢致邦 (XIE Zhibang) <[email protected]>
---
V1 -> V2: Update subject and message
src/evaluate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/evaluate.c +1 -1
@@ -6048,7 +6048,7 @@ static const char * const cmd_op_name[] = {static const char *cmd_op_to_name (enum cmd_ops op) { -if (op >CMD_DESCRIBE ) +if (op >CMD_DESTROY )return "unknown" ;return cmd_op_name[op];
Signature · 1 line
2.43.0
Phil Sutter
reviewerQuoted 22 lines · 谢致邦 (XIE Zhibang)
Example:
nft --debug=all destroy table ip missingtableBefore:
Evaluate unknownAfter:
Evaluate destroyFixes e1dfd5cc4c46 ("src: add support to command "destroy"")Signed-off-by 谢致邦 (XIE Zhibang) <[email protected]>---
V1 -> V2: Update subject and messagesrc/evaluate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/evaluate.c +0
-0
src/evaluate.c static const char * const cmd_op_name[] = { · line 6054
Quoted 8 lines
src/evaluate.c +1
-1@@ -6048,7 +6048,7 @@ static const char * const cmd_op_name[] = {static const char *cmd_op_to_name (enum cmd_ops op) { -if (op >CMD_DESCRIBE ) +if (op >CMD_DESTROY )return "unknown" ;return cmd_op_name[op];
Maybe eliminate this source of error once and for all by making it:
| if (op >= array_size(cmd_op_name)
We may still return a NULL pointer if there are uninitialized array elements, but it's used for format strings only so should not harm.
Cheers, Phil