about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/math.c26
-rw-r--r--Src/params.c52
2 files changed, 39 insertions, 39 deletions
diff --git a/Src/math.c b/Src/math.c
index eee21e146..37981cf22 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -893,25 +893,6 @@ getcvar(char *s)
     return mn;
 }
 
-
-/* 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)
@@ -947,13 +928,6 @@ 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) {
 	/*
diff --git a/Src/params.c b/Src/params.c
index 4d33660fb..5058695bb 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2695,6 +2695,37 @@ gethkparam(char *s)
 }
 
 /**/
+static void
+check_warn_create(Param pm, const char *pmtype)
+{
+    Funcstack i;
+    const char *name;
+
+    if (pm->level != 0)
+	return;
+
+    name = NULL;
+    for (i = funcstack; i; i = i->prev) {
+	if (i->tp == FS_FUNC) {
+	    DPUTS(!i->name, "funcstack entry with no name");
+	    name = i->name;
+	    break;
+	}
+    }
+
+    if (name)
+    {
+	zwarn("%s parameter %s created globally in function %s",
+	      pmtype, pm->node.nam, name);
+    }
+    else
+    {
+	zwarn("%s parameter %s created globally in function",
+	      pmtype, pm->node.nam);
+    }
+}
+
+/**/
 mod_export Param
 assignsparam(char *s, char *val, int flags)
 {
@@ -2747,9 +2778,8 @@ assignsparam(char *s, char *val, int flags)
 	zsfree(val);
 	return NULL;
     }
-    if ((flags & ASSPM_WARN_CREATE) && v->pm->level == 0)
-	zwarn("scalar parameter %s created globally in function",
-	      v->pm->node.nam);
+    if (flags & ASSPM_WARN_CREATE)
+	check_warn_create(v->pm, "scalar");
     if (flags & ASSPM_AUGMENT) {
 	if (v->start == 0 && v->end == -1) {
 	    switch (PM_TYPE(v->pm->node.flags)) {
@@ -2898,9 +2928,8 @@ assignaparam(char *s, char **val, int flags)
 	    return NULL;
 	}
 
-    if ((flags & ASSPM_WARN_CREATE) && v->pm->level == 0)
-	zwarn("array parameter %s created globally in function",
-	      v->pm->node.nam);
+    if (flags & ASSPM_WARN_CREATE)
+	check_warn_create(v->pm, "array");
     if (flags & ASSPM_AUGMENT) {
     	if (v->start == 0 && v->end == -1) {
 	    if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) {
@@ -2958,9 +2987,8 @@ sethparam(char *s, char **val)
     queue_signals();
     if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) {
 	createparam(t, PM_HASHED);
-	if (isset(WARNCREATEGLOBAL) && locallevel > 0 && v->pm->level == 0)
-	    zwarn("associative array parameter %s created globally in function",
-		  v->pm->node.nam);
+	if (isset(WARNCREATEGLOBAL) && locallevel > 0)
+	    check_warn_create(v->pm, "associative array");
     } else if (!(PM_TYPE(v->pm->node.flags) & PM_HASHED) &&
 	     !(v->pm->node.flags & PM_SPECIAL)) {
 	unsetparam(t);
@@ -3032,10 +3060,8 @@ setnparam(char *s, mnumber val)
 	}
 	v = getvalue(&vbuf, &t, 1);
 	DPUTS(!v, "BUG: value not found for new parameter");
-	if (!was_unset && isset(WARNCREATEGLOBAL) && locallevel > 0 &&
-	    v->pm->level == 0)
-	    zwarn("numeric parameter %s created globally in function",
-		  v->pm->node.nam);
+	if (!was_unset && isset(WARNCREATEGLOBAL) && locallevel > 0)
+	    check_warn_create(v->pm, "numeric parameter");
     }
     setnumvalue(v, val);
     unqueue_signals();