From 3937fc9c265632810745124a6943f5e98d5da4e6 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Wed, 4 May 2011 22:12:22 +0000 Subject: [PATCH] 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) --- bin/sh/arith_yacc.c | 2 ++ tools/regression/bin/sh/expansion/set-u3.0 | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 tools/regression/bin/sh/expansion/set-u3.0 diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c index edb321ff05f..63f236c5611 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 00000000000..7f199b42c79 --- /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" ]