From 62b76bf31aa79db6b16e9c6601b89f821bf970f1 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 6 Aug 2016 01:20:37 +0100 Subject: improve option test coverage futher --- utils/nsoption.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/utils/nsoption.c b/utils/nsoption.c index e4354bf3f..6754d2131 100644 --- a/utils/nsoption.c +++ b/utils/nsoption.c @@ -822,14 +822,22 @@ nsoption_snoptionf(char *string, int fmtc = 0; /* current index into format string */ struct nsoption_s *option; - if (option_idx >= NSOPTION_LISTEND) { + if (fmt == NULL) { return -1; } - option = &nsoptions[option_idx]; /* assume the global table */ - if (option == NULL || option->key == NULL) + if ((option_idx < 0) || (option_idx >= NSOPTION_LISTEND)) { + return -1; + } + + if (nsoptions == NULL) { return -1; + } + option = &nsoptions[option_idx]; /* assume the global table */ + if (option == NULL || option->key == NULL) { + return -1; + } while ((slen < size) && (fmt[fmtc] != 0)) { if (fmt[fmtc] == '%') { -- cgit v1.2.3