Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Fix PR bin/48202 [non-critical/low]:
details: https://anonhg.NetBSD.org/src/rev/e70c6675a485
branches: trunk
changeset: 790413:e70c6675a485
user: ast <ast%NetBSD.org@localhost>
date: Sun Oct 06 21:05:50 2013 +0000
description:
Fix PR bin/48202 [non-critical/low]:
sh +nounset and `for X; do` iteration fails if parameter set empty
by applying and testing FreeBSD's patch of Oct 24 2009 for this; see
http://svnweb.freebsd.org/base/head/bin/sh/expand.c?r1=198453&r2=198454
Also created an ATF test in tests/bin/sh/t_expand.sh for this error and
corrected a space->tabs problem there as well.
diffstat:
bin/sh/expand.c | 6 +++---
tests/bin/sh/t_expand.sh | 18 ++++++++++++++++--
2 files changed, 19 insertions(+), 5 deletions(-)
diffs (70 lines):
diff -r a876c3d5a88e -r e70c6675a485 bin/sh/expand.c
--- a/bin/sh/expand.c Sun Oct 06 17:25:34 2013 +0000
+++ b/bin/sh/expand.c Sun Oct 06 21:05:50 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.89 2013/10/02 19:52:58 christos Exp $ */
+/* $NetBSD: expand.c,v 1.90 2013/10/06 21:05:50 ast Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
#else
-__RCSID("$NetBSD: expand.c,v 1.89 2013/10/02 19:52:58 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.90 2013/10/06 21:05:50 ast Exp $");
#endif
#endif /* not lint */
@@ -667,7 +667,7 @@
varlen = 0;
startloc = expdest - stackblock();
- if (!set && uflag) {
+ if (!set && uflag && *var != '@' && *var != '*') {
switch (subtype) {
case VSNORMAL:
case VSTRIMLEFT:
diff -r a876c3d5a88e -r e70c6675a485 tests/bin/sh/t_expand.sh
--- a/tests/bin/sh/t_expand.sh Sun Oct 06 17:25:34 2013 +0000
+++ b/tests/bin/sh/t_expand.sh Sun Oct 06 21:05:50 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_expand.sh,v 1.2 2013/10/06 21:05:50 ast Exp $
#
# Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -37,7 +37,7 @@
else
str="${str} >$1<"
fi
- shift
+ shift
done
echo ${str}
}
@@ -119,10 +119,24 @@
atf_check_equal '9223372036854775807' '$(((1 << 63) - 1))'
}
+atf_test_case iteration_on_null_parameter
+iteration_on_null_parameter_head() {
+ atf_set "descr" "Check iteration of \$@ in for loop when set to null;" \
+ "the error \"sh: @: parameter not set\" is incorrect." \
+ "PR bin/48202."
+}
+iteration_on_null_parameter_body() {
+ s1=`/bin/sh -uc 'N=; set -- ${N}; for X; do echo "[$X]"; done' 2>&1`
+ s2=`/bin/sh -uc 'N=; set -- ${N:-}; for X; do echo "[$X]"; done' 2>&1`
+ atf_check_equal '' '$s1'
+ atf_check_equal '[]' '$s2'
+}
+
atf_init_test_cases() {
atf_add_test_case dollar_at
atf_add_test_case dollar_at_with_text
atf_add_test_case strip
atf_add_test_case varpattern_backslashes
atf_add_test_case arithmetic
+ atf_add_test_case iteration_on_null_parameter
}
Home |
Main Index |
Thread Index |
Old Index