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)
This commit is contained in:
Jilles Tjoelker 2011-05-04 22:12:22 +00:00
parent 5a816b92a3
commit 3937fc9c26
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=221463
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -0,0 +1,6 @@
# $FreeBSD$
set -u
unset x
v=$( (eval ': $((x))') 2>&1 >/dev/null)
[ $? -ne 0 ] && [ -n "$v" ]