From 56b40679304df9c4bfcfd5764af24f1d35b86142 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 20 Jun 2017 23:56:50 +0000 Subject: *: 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 --- ospfclient/ospfclient.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ospfclient/ospfclient.c') diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c index d8d0fe8d47..affcbc9d6a 100644 --- a/ospfclient/ospfclient.c +++ b/ospfclient/ospfclient.c @@ -267,7 +267,7 @@ ism_change_callback (struct in_addr ifaddr, struct in_addr area_id, { printf ("ism_change: ifaddr: %s ", inet_ntoa (ifaddr)); printf ("area_id: %s\n", inet_ntoa (area_id)); - printf ("state: %d [%s]\n", state, LOOKUP (ospf_ism_state_msg, state)); + printf ("state: %d [%s]\n", state, lookup_msg(ospf_ism_state_msg, state, NULL)); } static void @@ -277,7 +277,7 @@ nsm_change_callback (struct in_addr ifaddr, struct in_addr nbraddr, printf ("nsm_change: ifaddr: %s ", inet_ntoa (ifaddr)); printf ("nbraddr: %s\n", inet_ntoa (nbraddr)); printf ("router_id: %s\n", inet_ntoa (router_id)); - printf ("state: %d [%s]\n", state, LOOKUP (ospf_nsm_state_msg, state)); + printf ("state: %d [%s]\n", state, lookup_msg(ospf_nsm_state_msg, state, NULL)); } -- cgit v1.2.3