summaryrefslogtreecommitdiffstats
path: root/lib/grammar_sandbox.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-06-21 01:56:50 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-06-21 17:22:21 +0200
commit56b40679304df9c4bfcfd5764af24f1d35b86142 (patch)
tree755de54cbc890545f73efe5f1f4d1843506d1860 /lib/grammar_sandbox.c
parentMerge pull request #730 from opensourcerouting/rbtree-improvement (diff)
downloadfrr-56b40679304df9c4bfcfd5764af24f1d35b86142.tar.xz
frr-56b40679304df9c4bfcfd5764af24f1d35b86142.zip
*: simplify log message lookup
log.c provides functionality for associating a constant (typically a protocol constant) with a string and finding the string given the constant. However this is highly delicate code that is extremely prone to stack overflows and off-by-one's due to requiring the developer to always remember to update the array size constant and to do so correctly which, as shown by example, is never a good idea.b The original goal of this code was to try to implement lookups in O(1) time without a linear search through the message array. Since this code is used 99% of the time for debugs, it's worth the 5-6 additional cmp's worst case if it means we avoid explitable bugs due to oversights... Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/grammar_sandbox.c')
-rw-r--r--lib/grammar_sandbox.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
index cfc3fb798..f4a8df26c 100644
--- a/lib/grammar_sandbox.c
+++ b/lib/grammar_sandbox.c
@@ -503,9 +503,8 @@ struct message tokennames[] = {
item(JOIN_TKN),
item(START_TKN), // first token in line
item(END_TKN), // last token in line
- { 0, NULL }
+ { 0 }
};
-size_t tokennames_max = array_size(tokennames);
/**
* Pretty-prints a graph, assuming it is a tree.
@@ -522,7 +521,7 @@ pretty_print_graph (struct vty *vty, struct graph_node *start, int level,
struct cmd_token *tok = start->data;
snprintf(tokennum, sizeof(tokennum), "%d?", tok->type);
- vty_out(vty, "%s", LOOKUP_DEF(tokennames, tok->type, tokennum));
+ vty_out(vty, "%s", lookup_msg(tokennames, tok->type, NULL));
if (tok->text)
vty_out(vty, ":\"%s\"", tok->text);
if (tok->varname)
@@ -591,7 +590,7 @@ pretty_print_dot (FILE *ofd, unsigned opts, struct graph_node *start,
snprintf(tokennum, sizeof(tokennum), "%d?", tok->type);
fprintf(ofd, " n%p [ shape=box, label=<", start);
- fprintf(ofd, "<b>%s</b>", LOOKUP_DEF(tokennames, tok->type, tokennum));
+ fprintf(ofd, "<b>%s</b>", lookup_msg(tokennames, tok->type, NULL));
if (tok->attr == CMD_ATTR_DEPRECATED)
fprintf(ofd, " (d)");
else if (tok->attr == CMD_ATTR_HIDDEN)