diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-06-20 23:56:50 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-06-21 15:22:21 +0000 |
| commit | 56b40679304df9c4bfcfd5764af24f1d35b86142 (patch) | |
| tree | 755de54cbc890545f73efe5f1f4d1843506d1860 /lib/log.h | |
| parent | d368cd48b94cb9a22b9733200d8cfd94c71338ce (diff) | |
*: 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/log.h')
| -rw-r--r-- | lib/log.h | 9 |
1 files changed, 1 insertions, 8 deletions
@@ -99,14 +99,7 @@ extern int zlog_reset_file (void); /* Rotate log. */ extern int zlog_rotate (void); -/* For hackey message lookup and check */ -#define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x) -#define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)") - -extern const char *lookup (const struct message *, int); -extern const char *mes_lookup (const struct message *meslist, - int max, int index, - const char *no_item, const char *mesname); +const char *lookup_msg (const struct message *mz, int kz, const char *nf); /* Safe version of strerror -- never returns NULL. */ extern const char *safe_strerror(int errnum); |
