lint: clean up check for getopt
The original options string is not needed during the check. Having only the unhandled options suffices. No functional change.
This commit is contained in:
parent
46a713f776
commit
7f300e59ba
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ckgetopt.c,v 1.4 2021/02/20 09:57:02 rillig Exp $ */
|
||||
/* $NetBSD: ckgetopt.c,v 1.5 2021/02/20 10:01:27 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2021 The NetBSD Foundation, Inc.
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: ckgetopt.c,v 1.4 2021/02/20 09:57:02 rillig Exp $");
|
||||
__RCSID("$NetBSD: ckgetopt.c,v 1.5 2021/02/20 10:01:27 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
@ -61,12 +61,11 @@ struct {
|
||||
|
||||
/*
|
||||
* The options string from the getopt call. Whenever an option is
|
||||
* handled by a case label, it is set to ' ' in unhandled_options.
|
||||
* In the end, only ' ' and ':' should remain in unhandled_options.
|
||||
* handled by a case label, it is set to ' '. In the end, only ' '
|
||||
* and ':' should remain.
|
||||
*/
|
||||
pos_t options_pos;
|
||||
char *options;
|
||||
char *unhandled_options;
|
||||
|
||||
/*
|
||||
* The nesting level of switch statements, is only modified if
|
||||
@ -123,9 +122,9 @@ check_unlisted_option(char opt)
|
||||
if (opt == '?')
|
||||
return;
|
||||
|
||||
const char *optptr = strchr(ck.options, opt);
|
||||
char *optptr = strchr(ck.options, opt);
|
||||
if (optptr != NULL)
|
||||
ck.unhandled_options[optptr - ck.options] = ' ';
|
||||
*optptr = ' ';
|
||||
else {
|
||||
/* option '%c' should be listed in the options string */
|
||||
warning(339, opt);
|
||||
@ -136,9 +135,9 @@ check_unlisted_option(char opt)
|
||||
static void
|
||||
check_unhandled_option(void)
|
||||
{
|
||||
lint_assert(ck.unhandled_options != NULL);
|
||||
lint_assert(ck.options != NULL);
|
||||
|
||||
for (const char *opt = ck.unhandled_options; *opt != '\0'; opt++) {
|
||||
for (const char *opt = ck.options; *opt != '\0'; opt++) {
|
||||
if (*opt == ' ' || *opt == ':')
|
||||
continue;
|
||||
|
||||
@ -157,7 +156,6 @@ check_getopt_begin_while(const tnode_t *tn)
|
||||
if (ck.while_level == 0) {
|
||||
if (!is_getopt_call(tn, &ck.options))
|
||||
return;
|
||||
ck.unhandled_options = xstrdup(ck.options);
|
||||
ck.options_pos = curr_pos;
|
||||
}
|
||||
ck.while_level++;
|
||||
@ -200,7 +198,5 @@ check_getopt_end_while(void)
|
||||
return;
|
||||
|
||||
free(ck.options);
|
||||
free(ck.unhandled_options);
|
||||
ck.options = NULL;
|
||||
ck.unhandled_options = NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user