From a0331edcefb46a2f6451d8000b48f17ea7342a53 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 11 Feb 2019 21:24:40 +0100 Subject: get_value_string(): guard against NULL get_value_string() conveniently prints the value number to a static buffer if it is unknown in a value_string array. Do the same if the value_string array pointer itself is NULL. If a value string array is user supplied and might be NULL, one could add a separate NULL check around it; but by making get_value_string() itself guard against NULL, another static char buffer to print the value number is avoided. Change-Id: Ie640e9258a959da8f4f9089478de993509853997 --- src/utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils.c b/src/utils.c index 0b2ed31d..2d5bcb0e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -73,6 +73,9 @@ const char *get_value_string_or_null(const struct value_string *vs, { int i; + if (!vs) + return NULL; + for (i = 0;; i++) { if (vs[i].value == 0 && vs[i].str == NULL) break; -- cgit v1.2.3