Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: warn if a getopt switch tries to h...



details:   https://anonhg.NetBSD.org/src/rev/ca3124c7b775
branches:  trunk
changeset: 1024085:ca3124c7b775
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 09 14:22:42 2021 +0000

description:
lint: warn if a getopt switch tries to handle unreachable ':'

diffstat:

 tests/usr.bin/xlint/lint1/msg_338.c   |  4 ++--
 tests/usr.bin/xlint/lint1/msg_338.exp |  1 +
 usr.bin/xlint/lint1/ckgetopt.c        |  9 ++++++---
 3 files changed, 9 insertions(+), 5 deletions(-)

diffs (63 lines):

diff -r ce853bc1474a -r ca3124c7b775 tests/usr.bin/xlint/lint1/msg_338.c
--- a/tests/usr.bin/xlint/lint1/msg_338.c       Sat Oct 09 13:57:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_338.c       Sat Oct 09 14:22:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_338.c,v 1.6 2021/10/09 13:57:55 rillig Exp $       */
+/*     $NetBSD: msg_338.c,v 1.7 2021/10/09 14:22:42 rillig Exp $       */
 # 3 "msg_338.c"
 
 // Test for message: option '%c' should be handled in the switch [338]
@@ -141,7 +141,7 @@
        /* expect+1: warning: option 'b' should be handled in the switch [338] */
        while ((c = getopt(argc, argv, "b:")) != -1) {
                switch (c) {
-               /* TODO: expect+1: warning: option ':' should be listed in the options string [339] */
+               /* expect+1: warning: option ':' should be listed in the options string [339] */
                case ':':
                        return 'm';
                default:
diff -r ce853bc1474a -r ca3124c7b775 tests/usr.bin/xlint/lint1/msg_338.exp
--- a/tests/usr.bin/xlint/lint1/msg_338.exp     Sat Oct 09 13:57:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_338.exp     Sat Oct 09 14:22:42 2021 +0000
@@ -4,4 +4,5 @@
 msg_338.c(14): warning: option 'd' should be handled in the switch [338]
 msg_338.c(94): warning: option 'o' should be handled in the switch [338]
 msg_338.c(116): warning: option 'o' should be handled in the switch [338]
+msg_338.c(145): warning: option ':' should be listed in the options string [339]
 msg_338.c(142): warning: option 'b' should be handled in the switch [338]
diff -r ce853bc1474a -r ca3124c7b775 usr.bin/xlint/lint1/ckgetopt.c
--- a/usr.bin/xlint/lint1/ckgetopt.c    Sat Oct 09 13:57:55 2021 +0000
+++ b/usr.bin/xlint/lint1/ckgetopt.c    Sat Oct 09 14:22:42 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.11 2021/08/22 22:15:07 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.12 2021/10/09 14:22:42 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.11 2021/08/22 22:15:07 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.12 2021/10/09 14:22:42 rillig Exp $");
 #endif
 
 #include <stdbool.h>
@@ -113,13 +113,16 @@
 {
        lint_assert(ck.options != NULL);
 
+       if (opt == ':' && ck.options[0] != ':')
+               goto warn;
+
        char *optptr = strchr(ck.options, opt);
        if (optptr != NULL)
                *optptr = ' ';
        else if (opt != '?') {
+       warn:
                /* option '%c' should be listed in the options string */
                warning(339, opt);
-               return;
        }
 }
 



Home | Main Index | Thread Index | Old Index