diff options
author | Miguel Sofer <miguel.sofer@gmail.com> | 2004-04-28 13:11:28 (GMT) |
---|---|---|
committer | Miguel Sofer <miguel.sofer@gmail.com> | 2004-04-28 13:11:28 (GMT) |
commit | 74c3e73d8d217092ccc418bd990bf43f9d8890ce (patch) | |
tree | 81765be95085309d4c8abe150311d739005cb45c /generic/tclVar.c | |
parent | 25b3a8473ed731844f2c5f093d1156a80c82e848 (diff) | |
download | tcl-74c3e73d8d217092ccc418bd990bf43f9d8890ce.zip tcl-74c3e73d8d217092ccc418bd990bf43f9d8890ce.tar.gz tcl-74c3e73d8d217092ccc418bd990bf43f9d8890ce.tar.bz2 |
* doc/global.n:
* doc/upvar.n:
* generic/tclVar.c (ObjMakeUpvar):
* tests/upvar.test (upvar-8.11):
* tests/var.test (var-3.11): Avoid creation of unusable variables:
[Bug 600812] [TIP 184].
Diffstat (limited to 'generic/tclVar.c')
-rw-r--r-- | generic/tclVar.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c index 1b3068b..b3dbbee 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclVar.c,v 1.78 2004/04/06 22:25:56 dgp Exp $ + * RCS: @(#) $Id: tclVar.c,v 1.79 2004/04/28 13:11:33 msofer Exp $ */ #include "tclInt.h" @@ -3321,6 +3321,7 @@ ObjMakeUpvar(interp, framePtr, otherP1Ptr, otherP2, otherFlags, myName, myFlags, Var *otherPtr, *varPtr, *arrayPtr; CallFrame *varFramePtr; CONST char *errMsg; + CONST char *p; /* * Find "other" in "framePtr". If not looking up other in just the @@ -3367,6 +3368,29 @@ ObjMakeUpvar(interp, framePtr, otherP1Ptr, otherP2, otherFlags, myName, myFlags, } /* + * Do not permit the new variable to look like an array reference, + * as it will not be reachable in that case [Bug 600812, TIP 184]. + * The "definition" of what "looks like an array reference" is + * consistent (and must remain consistent) with the code in + * TclObjLookupVar(). + */ + + p = strstr(myName, "("); + if (p != NULL) { + p += strlen(p)-1; + if (*p == ')') { + /* + * myName looks like an array reference. + */ + + Tcl_AppendResult((Tcl_Interp *) iPtr, "bad variable name \"", + myName, "\": upvar won't create a scalar variable that ", + "looks like an array element", (char *) NULL); + return TCL_ERROR; + } + } + + /* * Lookup and eventually create the new variable. Set the flag bit * LOOKUP_FOR_UPVAR to indicate the special resolution rules for * upvar purposes: |