From 48394b08a7aab1b86bf721b8bb95979824cd8e9f Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Thu, 14 May 2020 17:16:09 -0400 Subject: [PATCH] commit bash-20200512 snapshot --- CWRU/CWRU.chlog | 13 +++++++++++++ doc/bash.1 | 5 +++-- doc/bashref.texi | 9 +++++---- test.c | 20 +++++++++++--------- test.h | 12 ++++++------ tests/test.right | 2 +- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index c012cf37..1a2b10ee 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8347,3 +8347,16 @@ support/config.{guess,sub} configure.ac - add support for `genode' from Emery Hemingway + + 5/14 + ---- +test.c + - term: fix case where an argument that looks like a unary operator, + but doesn't have enough tokens left to have an argument to that + operator, was not being treated as a one-argument test. Affects + only uses of test with four and greater arguments, which posix says + are unspecified. This is a bug, or at least an incompatibility, at + least 30 years old. + - test_command: if there are unconsumed arguments, call test_syntax_error + with a `syntax error' argument if the first remaining argument starts + with a `-'. Better than a generic `too many arguments' error diff --git a/doc/bash.1 b/doc/bash.1 index 2d27a299..70871cbe 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -1187,8 +1187,9 @@ not been present. .PP A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq) will cause the string to be translated according to the current locale. -If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign -is ignored. +If the current locale is \fBC\fP or \fBPOSIX\fP, +or if there are no translations available, +the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted. .SH PARAMETERS diff --git a/doc/bashref.texi b/doc/bashref.texi index d5116480..394d0b02 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -533,10 +533,11 @@ been present. @cindex native languages @cindex translation, native languages -A double-quoted string preceded by a dollar sign (@samp{$}) will cause -the string to be translated according to the current locale. -If the current locale is @code{C} or @code{POSIX}, the dollar sign -is ignored. +A double-quoted string preceded by a dollar sign (@samp{$}) +will cause the string to be translated according to the current locale. +If the current locale is @code{C} or @code{POSIX}, +or if there are no translations available, +the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted. diff --git a/test.c b/test.c index 6cf356d5..ed1d3ffc 100644 --- a/test.c +++ b/test.c @@ -273,14 +273,11 @@ term () if ((pos + 3 <= argc) && test_binop (argv[pos + 1])) value = binary_operator (); - /* Might be a switch type argument */ - else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0') - { - if (test_unop (argv[pos])) - value = unary_operator (); - else - test_syntax_error (_("%s: unary operator expected"), argv[pos]); - } + /* Might be a switch type argument -- make sure we have enough arguments for + the unary operator and argument */ + else if ((pos + 2) <= argc && test_unop (argv[pos])) + value = unary_operator (); + else { value = argv[pos][0] != '\0'; @@ -894,7 +891,12 @@ test_command (margc, margv) value = posixtest (); if (pos != argc) - test_syntax_error (_("too many arguments"), (char *)NULL); + { + if (pos < argc && argv[pos][0] == '-') + test_syntax_error (_("syntax error: `%s' unexpected"), argv[pos]); + else + test_syntax_error (_("too many arguments"), (char *)NULL); + } test_exit (SHELL_BOOLEAN (value)); } diff --git a/test.h b/test.h index 626edc43..ea3c33e9 100644 --- a/test.h +++ b/test.h @@ -1,6 +1,6 @@ /* test.h -- external interface to the conditional command code. */ -/* Copyright (C) 1997-2009 Free Software Foundation, Inc. +/* Copyright (C) 1997-2020 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -28,12 +28,12 @@ #define TEST_ARITHEXP 0x02 #define TEST_LOCALE 0x04 -extern int test_unop __P((char *)); -extern int test_binop __P((char *)); +extern int test_unop PARAMS((char *)); +extern int test_binop PARAMS((char *)); -extern int unary_test __P((char *, char *)); -extern int binary_test __P((char *, char *, char *, int)); +extern int unary_test PARAMS((char *, char *)); +extern int binary_test PARAMS((char *, char *, char *, int)); -extern int test_command __P((int, char **)); +extern int test_command PARAMS((int, char **)); #endif /* _TEST_H_ */ diff --git a/tests/test.right b/tests/test.right index a3a20e23..391edbbd 100644 --- a/tests/test.right +++ b/tests/test.right @@ -268,7 +268,7 @@ b ( 1 = 2 2 ./test.tests: line 26: test: -A: unary operator expected 2 -./test.tests: line 26: test: too many arguments +./test.tests: line 26: test: syntax error: `-ne' unexpected 2 ./test.tests: line 26: test: too many arguments 2