From f08314c80041b5058dbfeb880191166b70c3b675 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 5 Jan 2024 14:01:52 +0100 Subject: [PATCH] mx_getopt: Remove a NULL pointer check The only caller of the static find_short_option() function doesn't calls it with a NULL pointer value as the third argument: idx = find_short_option(optctl->options, &optctl->_unhandled_shortopts, &optctl->optarg); So it is not necessary for the function to check the pointer for NULL. The disadvantage of doing is, that the llvm static analyzer concludes from the check, that it was possible that the function would be called with a NULL pointer and questiones a later access in the same function, which is unchecked: mx_getopt.c:158:16: warning: Dereference of null pointer (loaded from variable 'optarg') [core.NullDereference] *optarg = *name; ~~~~~~ ^ 1 warning generated. Remove the check. --- mx_getopt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mx_getopt.c b/mx_getopt.c index 1ef82c20..0f47b35c 100644 --- a/mx_getopt.c +++ b/mx_getopt.c @@ -127,8 +127,7 @@ static int find_short_option(struct mx_option *options, char **name, char **opta assert(short_opt); - if (optarg) - *optarg = NULL; + *optarg = NULL; for (i=0, idx=-1; options[i].long_opt || options[i].short_opt; i++) {