diff options
author | Peter Stephenson <pws@zsh.org> | 2015-04-15 10:20:06 +0100 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2015-04-15 10:20:06 +0100 |
commit | 2ef4b38461dfb554ed2226d9de8958703bc00b98 (patch) | |
tree | 0211f4c597eb0d95310b95b57191fc64fca79b4e | |
parent | a2c579050fbf40eb9192f043e901e6b2eff3ab50 (diff) | |
download | zsh-2ef4b38461dfb554ed2226d9de8958703bc00b98.tar.gz zsh-2ef4b38461dfb554ed2226d9de8958703bc00b98.tar.xz zsh-2ef4b38461dfb554ed2226d9de8958703bc00b98.zip |
34892 (slightly tweaked): math evaluation fix
An empty expression resulting from substitution includes a Nularg, which needs handling the same as an empty string.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Src/math.c | 4 | ||||
-rw-r--r-- | Test/C01arith.ztst | 5 |
3 files changed, 9 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index a5d8d7e85..e2d561105 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-04-15 Peter Stephenson <p.stephenson@samsung.com> + * 34892 (slightly tweaked): Src/math.c, Test/C01arith.ztst: fix + math evaluation with empty expression resulting from substitution. + * 34887: Src/exec, Test/E01options.ztst: assignments before "command special-builtin/func" in POSIX_BUILTINS mode behave as normal command. Tidy up case handling in code and add test. diff --git a/Src/math.c b/Src/math.c index c047725c5..2105180c8 100644 --- a/Src/math.c +++ b/Src/math.c @@ -1398,7 +1398,7 @@ matheval(char *s) if (!mlevel) outputradix = outputunderscore = 0; - if (!*s) { + if (!*s || *s == Nularg) { x.type = MN_INTEGER; x.u.l = 0; return x; @@ -1435,7 +1435,7 @@ mathevalarg(char *s, char **ss) * * To avoid a more opaque error further in, bail out here. */ - if (!*s) { + if (!*s || *s == Nularg) { zerr("bad math expression: empty string"); return (zlong)0; } diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst index d3176dd5e..e2dfe56fc 100644 --- a/Test/C01arith.ztst +++ b/Test/C01arith.ztst @@ -383,4 +383,7 @@ print ${$(( $1 * 100 ))%%.[0-9]#}) 0:Arithmetic substitution nested in parameter substitution >3246 - + + print $((`:`)) +0:Null string in arithmetic evaluation after command substitution +>0 |