mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-23 16:40:24 +02:00
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.
This commit is contained in:
parent
36abe20c0f
commit
2654cb43f6
5 changed files with 38 additions and 2 deletions
|
@ -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;
|
||||
|
|
25
Src/math.c
25
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) {
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue