Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: parse special options strictly
details: https://anonhg.NetBSD.org/src/rev/81cf0ababdff
branches: trunk
changeset: 1024875:81cf0ababdff
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Nov 07 18:09:56 2021 +0000
description:
indent: parse special options strictly
diffstat:
tests/usr.bin/indent/t_errors.sh | 17 +++++++----------
usr.bin/indent/args.c | 10 +++++-----
2 files changed, 12 insertions(+), 15 deletions(-)
diffs (86 lines):
diff -r 46554ad66377 -r 81cf0ababdff tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh Sun Nov 07 18:05:36 2021 +0000
+++ b/tests/usr.bin/indent/t_errors.sh Sun Nov 07 18:09:56 2021 +0000
@@ -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 @@
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
}
diff -r 46554ad66377 -r 81cf0ababdff usr.bin/indent/args.c
--- a/usr.bin/indent/args.c Sun Nov 07 18:05:36 2021 +0000
+++ b/usr.bin/indent/args.c Sun Nov 07 18:09:56 2021 +0000
@@ -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 @@
#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 @@
{
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 @@
return true;
}
- if (strncmp(arg, "st", 2) == 0) {
+ if (strcmp(arg, "st") == 0) {
if (input == NULL)
input = stdin;
if (output == NULL)
Home |
Main Index |
Thread Index |
Old Index