diff options
author | Daniel Shahaf <d.s@daniel.shahaf.name> | 2015-09-26 01:59:48 +0000 |
---|---|---|
committer | Daniel Shahaf <d.s@daniel.shahaf.name> | 2015-09-27 23:52:25 +0000 |
commit | 2654cb43f63349cff06b3dd26932dd76f53aed4c (patch) | |
tree | f08b52ed36e794ef7d8a42fca75a48ea2d2ebd32 /Src | |
parent | 36abe20c0f53015b816d5f3bdd1eeed713614233 (diff) | |
download | zsh-2654cb43f63349cff06b3dd26932dd76f53aed4c.tar.gz zsh-2654cb43f63349cff06b3dd26932dd76f53aed4c.tar.xz zsh-2654cb43f63349cff06b3dd26932dd76f53aed4c.zip |
36651: WARN_CREATE_GLOBAL += math expressions
Without this, '() { (( x=42 )) }' and '() { for (( i=0; … )) }' wouldn't warn about $x and $i, respectively, being created global.
Diffstat (limited to 'Src')
-rw-r--r-- | Src/exec.c | 3 | ||||
-rw-r--r-- | Src/math.c | 25 |
2 files changed, 27 insertions, 1 deletions
diff --git a/Src/exec.c b/Src/exec.c index 109a04a26..da808d6f1 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -176,7 +176,8 @@ mod_export int sfcontext; /**/ struct execstack *exstack; -/* Stack with names of functions currently active. */ +/* Stack with names of function calls, 'source' calls, and 'eval' calls + * currently active. */ /**/ mod_export Funcstack funcstack; diff --git a/Src/math.c b/Src/math.c index 977e92345..56565a629 100644 --- a/Src/math.c +++ b/Src/math.c @@ -894,6 +894,24 @@ getcvar(char *s) } +/* If script execution is inside a function call that hasn't returned, + * return the name of that function. Else return NULL. + */ + +/**/ +static const char * +in_function_call(void) +{ + Funcstack i; + for (i = funcstack; i; i = i->prev) + if (i->tp == FS_FUNC) { + DPUTS(!i->name, "funcstack entry with no name"); + return i->name; + } + + return NULL; +} + /**/ static mnumber setmathvar(struct mathvalue *mvp, mnumber v) @@ -929,6 +947,13 @@ setmathvar(struct mathvalue *mvp, mnumber v) if (noeval) return v; untokenize(mvp->lval); + if (isset(WARNCREATEGLOBAL)) { + const char *function_name; + if (!paramtab->getnode(paramtab, mvp->lval) && + (function_name = in_function_call())) + zwarn("math parameter %s created globally in function %s", + mvp->lval, function_name); + } pm = setnparam(mvp->lval, v); if (pm) { /* |