Module Name: src
Committed By: rillig
Date: Sat Feb 20 10:01:27 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/xlint/lint1/ckgetopt.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.4 src/usr.bin/xlint/lint1/ckgetopt.c:1.5
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.4 Sat Feb 20 09:57:02 2021
+++ src/usr.bin/xlint/lint1/ckgetopt.c Sat Feb 20 10:01:27 2021
@@ -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 *
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;
}