From 7f300e59ba518140d0c669b2bc3c75842f66575c Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 20 Feb 2021 10:01:27 +0000 Subject: [PATCH] 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. --- usr.bin/xlint/lint1/ckgetopt.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/usr.bin/xlint/lint1/ckgetopt.c b/usr.bin/xlint/lint1/ckgetopt.c index 51a8e1b09551..5abd93d1aa42 100644 --- a/usr.bin/xlint/lint1/ckgetopt.c +++ b/usr.bin/xlint/lint1/ckgetopt.c @@ -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 #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 @@ -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; }