Module Name: src Committed By: rillig Date: Sat Oct 9 14:22:42 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_338.c msg_338.exp src/usr.bin/xlint/lint1: ckgetopt.c Log Message: lint: warn if a getopt switch tries to handle unreachable ':' To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_338.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_338.exp cvs rdiff -u -r1.11 -r1.12 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/tests/usr.bin/xlint/lint1/msg_338.c diff -u src/tests/usr.bin/xlint/lint1/msg_338.c:1.6 src/tests/usr.bin/xlint/lint1/msg_338.c:1.7 --- src/tests/usr.bin/xlint/lint1/msg_338.c:1.6 Sat Oct 9 13:57:55 2021 +++ src/tests/usr.bin/xlint/lint1/msg_338.c Sat Oct 9 14:22:42 2021 @@ -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 @@ unreachable_colon(int argc, char **argv) /* 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: Index: src/tests/usr.bin/xlint/lint1/msg_338.exp diff -u src/tests/usr.bin/xlint/lint1/msg_338.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_338.exp:1.5 --- src/tests/usr.bin/xlint/lint1/msg_338.exp:1.4 Sat Oct 9 13:57:55 2021 +++ src/tests/usr.bin/xlint/lint1/msg_338.exp Sat Oct 9 14:22:42 2021 @@ -4,4 +4,5 @@ msg_338.c(14): warning: option 'c' shoul 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] Index: src/usr.bin/xlint/lint1/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.11 src/usr.bin/xlint/lint1/ckgetopt.c:1.12 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.11 Sun Aug 22 22:15:07 2021 +++ src/usr.bin/xlint/lint1/ckgetopt.c Sat Oct 9 14:22:42 2021 @@ -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 @@ check_unlisted_option(char opt) { 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; } }