Module Name: src
Committed By: rillig
Date: Thu Oct 28 21:02:05 UTC 2021
Modified Files:
src/tests/usr.bin/indent: t_errors.sh t_misc.sh
src/usr.bin/indent: args.c
Log Message:
indent: parse option '-cli' strictly
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/t_misc.sh
cvs rdiff -u -r1.62 -r1.63 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.5 src/tests/usr.bin/indent/t_errors.sh:1.6
--- src/tests/usr.bin/indent/t_errors.sh:1.5 Sun Oct 24 17:19:49 2021
+++ src/tests/usr.bin/indent/t_errors.sh Thu Oct 28 21:02:05 2021
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_errors.sh,v 1.5 2021/10/24 17:19:49 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.6 2021/10/28 21:02:05 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -135,6 +135,14 @@ option_int_trailing_garbage_body()
-i3garbage
}
+atf_test_case 'option_cli_trailing_garbage'
+option_cli_trailing_garbage_body()
+{
+ expect_error \
+ 'indent: Command line: argument "3garbage" to option "-cli" must be numeric' \
+ -cli3garbage
+}
+
atf_test_case 'option_buffer_overflow'
option_buffer_overflow_body()
{
@@ -354,6 +362,7 @@ atf_init_test_cases()
atf_add_test_case 'option_tabsize_large'
atf_add_test_case 'option_tabsize_very_large'
atf_add_test_case 'option_int_trailing_garbage'
+ atf_add_test_case 'option_cli_trailing_garbage'
atf_add_test_case 'option_indent_size_zero'
atf_add_test_case 'unterminated_comment'
atf_add_test_case 'in_place_wrong_backup'
Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.8 src/tests/usr.bin/indent/t_misc.sh:1.9
--- src/tests/usr.bin/indent/t_misc.sh:1.8 Sun Oct 24 17:19:49 2021
+++ src/tests/usr.bin/indent/t_misc.sh Thu Oct 28 21:02:05 2021
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_misc.sh,v 1.8 2021/10/24 17:19:49 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.9 2021/10/28 21:02:05 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -216,15 +216,11 @@ opt_body()
-T/* define
a type */custom_type
-/* For int options, trailing garbage would lead to an error message. */
+/* For int options, trailing garbage would be an error. */
-i3
-/*
- * For float options, trailing garbage is ignored.
- *
- * See atof.
- */
--cli3.5garbage
+/*For float options, trailing garbage would be an error. */
+-cli3.5
-b/*/acc /* The comment is '/' '*' '/', making the option '-bacc'. */
EOF
Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.62 src/usr.bin/indent/args.c:1.63
--- src/usr.bin/indent/args.c:1.62 Thu Oct 28 20:49:36 2021
+++ src/usr.bin/indent/args.c Thu Oct 28 21:02:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.62 2021/10/28 20:49:36 rillig Exp $ */
+/* $NetBSD: args.c,v 1.63 2021/10/28 21:02:04 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.62 2021/10/28 20:49:36 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.63 2021/10/28 21:02:04 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
#endif
@@ -73,12 +73,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
#define int_option(name, var, min, max) \
{name, false, false, false, min, max, assert_type(&(opt.var), int *)}
-/*
- * N.B.: an option whose name is a prefix of another option must come earlier;
- * for example, "l" must come before "lp".
- *
- * See set_special_option for special options.
- */
+/* See set_special_option for special options. */
static const struct pro {
const char p_name[5]; /* e.g. "bl", "cli" */
bool p_is_bool;
@@ -170,7 +165,11 @@ set_special_option(const char *arg, cons
arg_end = arg + 3;
if (arg_end[0] == '\0')
goto need_param;
- opt.case_indent = (float)atof(arg_end);
+ char *end;
+ opt.case_indent = (float)strtod(arg_end, &end);
+ if (*end != '\0')
+ errx(1, "%s: argument \"%s\" to option \"-%.*s\" must be numeric",
+ option_source, arg_end, (int)(arg_end - arg), arg);
return true;
}