Module Name: src Committed By: rillig Date: Sun Nov 7 18:09:56 UTC 2021
Modified Files: src/tests/usr.bin/indent: t_errors.sh src/usr.bin/indent: args.c Log Message: indent: parse special options strictly To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/tests/usr.bin/indent/t_errors.sh cvs rdiff -u -r1.69 -r1.70 src/usr.bin/indent/args.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/indent/t_errors.sh diff -u src/tests/usr.bin/indent/t_errors.sh:1.19 src/tests/usr.bin/indent/t_errors.sh:1.20 --- src/tests/usr.bin/indent/t_errors.sh:1.19 Sun Nov 7 15:54:00 2021 +++ src/tests/usr.bin/indent/t_errors.sh Sun Nov 7 18:09:56 2021 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: t_errors.sh,v 1.19 2021/11/07 15:54:00 rillig Exp $ +# $NetBSD: t_errors.sh,v 1.20 2021/11/07 18:09:56 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -146,27 +146,24 @@ option_cli_trailing_garbage_body() atf_test_case 'option_npro_trailing_garbage' option_npro_trailing_garbage_body() { - # TODO: reject -npro-garbage, only allow -npro without trailing garbage. - - atf_check \ + atf_check -s 'exit:1' \ + -e 'inline:indent: Command line: unknown option "-npro-garbage"'"$nl" \ "$indent" -npro-garbage } atf_test_case 'option_st_trailing_garbage' option_st_trailing_garbage_body() { - # TODO: reject -stdio, only allow -st without trailing garbage. - - atf_check \ + atf_check -s 'exit:1' \ + -e 'inline:indent: Command line: unknown option "-stdio"'"$nl" \ "$indent" -stdio } atf_test_case 'option_version_trailing_garbage' option_version_trailing_garbage_body() { - # TODO: reject --version-dump, only allow --version without trailing garbage. - - atf_check -o 'inline:NetBSD indent 2.1'"$nl" \ + atf_check -s 'exit:1' \ + -e 'inline:indent: Command line: unknown option "--version-dump"'"$nl" \ "$indent" --version-dump } Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.69 src/usr.bin/indent/args.c:1.70 --- src/usr.bin/indent/args.c:1.69 Fri Nov 5 21:52:17 2021 +++ src/usr.bin/indent/args.c Sun Nov 7 18:09:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.69 2021/11/05 21:52:17 rillig Exp $ */ +/* $NetBSD: args.c,v 1.70 2021/11/07 18:09:56 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.69 2021/11/05 21:52:17 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.70 2021/11/07 18:09:56 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -152,12 +152,12 @@ set_special_option(const char *arg, cons { const char *arg_end; - if (strncmp(arg, "-version", 8) == 0) { + if (strcmp(arg, "-version") == 0) { printf("NetBSD indent 2.1\n"); exit(0); } - if (arg[0] == 'P' || strncmp(arg, "npro", 4) == 0) + if (arg[0] == 'P' || strcmp(arg, "npro") == 0) return true; if (strncmp(arg, "cli", 3) == 0) { @@ -172,7 +172,7 @@ set_special_option(const char *arg, cons return true; } - if (strncmp(arg, "st", 2) == 0) { + if (strcmp(arg, "st") == 0) { if (input == NULL) input = stdin; if (output == NULL)