From: Peter Avalos Date: Sun, 3 Jul 2011 00:07:08 +0000 (-1000) Subject: sh: Apply set -u to variables in arithmetic. X-Git-Tag: v2.12.0~180 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/024481c1f7126a45bec71491e1287c2fff512050 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. Obtained-from: FreeBSD SVN rev 221463 --- diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c index dd8a37368c..1dd364cc49 100644 --- a/bin/sh/arith_yacc.c +++ b/bin/sh/arith_yacc.c @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/bin/sh/arith_yacc.c,v 1.3 2011/03/05 13:27:13 jilles Exp $ + * $FreeBSD: src/bin/sh/arith_yacc.c,v 1.4 2011/05/04 22:12:22 jilles Exp $ */ #include @@ -98,6 +98,8 @@ 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 0000000000..cc0bd1bdde --- /dev/null +++ b/tools/regression/bin/sh/expansion/set-u3.0 @@ -0,0 +1,6 @@ +# $FreeBSD: src/tools/regression/bin/sh/expansion/set-u3.0,v 1.1 2011/05/04 22:12:22 jilles Exp $ + +set -u +unset x +v=$( (eval ': $((x))') 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ]