Skip to content

Commit

Permalink
mx_getopt: Remove a NULL pointer check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed Jan 10, 2024
1 parent 3565e85 commit f08314c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions mx_getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {

Expand Down

0 comments on commit f08314c

Please sign in to comment.