summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-05-04 22:12:22 +0000
committerjilles <jilles@FreeBSD.org>2011-05-04 22:12:22 +0000
commitba0d29571f9f8f83653cd0298a96664fe82e0e04 (patch)
treeb5d34d5bbcadf2e334bbcb6aceab0acd2258ee47
parent48e83eacf3f56abcf0a13583eb07ea21151165b3 (diff)
downloadFreeBSD-src-ba0d29571f9f8f83653cd0298a96664fe82e0e04.zip
FreeBSD-src-ba0d29571f9f8f83653cd0298a96664fe82e0e04.tar.gz
sh: Apply set -u to variables in arithmetic.
Note that this only applies to variables that are actually used. Things like (0 && unsetvar) do not cause an error. Exp-run done by: pav (with some other sh(1) changes)
-rw-r--r--bin/sh/arith_yacc.c2
-rw-r--r--tools/regression/bin/sh/expansion/set-u3.06
2 files changed, 8 insertions, 0 deletions
diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c
index edb321f..63f236c 100644
--- a/bin/sh/arith_yacc.c
+++ b/bin/sh/arith_yacc.c
@@ -97,6 +97,8 @@ static arith_t arith_lookupvarint(char *varname)
arith_t result;
str = lookupvar(varname);
+ if (uflag && str == NULL)
+ yyerror("variable not set");
if (str == NULL || *str == '\0')
str = "0";
errno = 0;
diff --git a/tools/regression/bin/sh/expansion/set-u3.0 b/tools/regression/bin/sh/expansion/set-u3.0
new file mode 100644
index 0000000..7f199b4
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/set-u3.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -u
+unset x
+v=$( (eval ': $((x))') 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]
OpenPOWER on IntegriCloud