empty name array setting failure within namespace procedure
Closed / Fixed218965ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:08:41
OriginalBugID: 3339 Bug
Version: 8.2.1
SubmitDate: '1999-11-05'
LastModified: '1999-12-09'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 2551
OS: Linux-Red Hat
FixedDate: '1999-12-09'
FixedInVersion: 8.3b1
ClosedDate: '2000-10-25'
Name:
Jean-Luc Fontaine
Comments:
bug also present in 8.0 and 8.1 releases
ReproducibleScript:
namespace eval n {
proc p {} {
variable {}
set (0) 0
set (1) 1
set n 2
set ($n) 2
set ($n,foo) 2
}
p
parray {}
}
ObservedBehavior:
ouput:
(0) = 0
(2,foo) = 2
DesiredBehavior:
output:
(0) = 0
(1) = 1
(2) = 2
(2,foo) = 2
More info from Jean-Luc:
I found what happened in tclCompile.c, TclFindCompiledLocal():
...
for (i = 0; i < localCt; i++) {
if (!TclIsVarTemporary(localPtr)) {
char *localName = localPtr->name;
if ((name[0] == localName[0])
&& (nameBytes == localPtr->nameLength)
&& (strncmp(name, localName, (unsigned) nameBytes) == 0)) {
return i;
}
}
localPtr = localPtr->nextPtr;
}
...
For the following Tcl source code:
namespace eval n {proc p {} {variable {}; set (a) 0; set (b) 1}}
if we look at what happens at the following line:
if ((name[0] == localName[0])
For (a), name is "(a) 0; set (b) 1" and we never get there, which is normal since the {} array is not yet allocated. For (b), name is "(b) 1" and since localName is "" (empty name array allocated at the (a) occurence), comparing the first characters ('(' and '\0') is wrong. The fix consists in removing the test on the first byte.
-----
This is correct, that slight opt breaks the {} array name case,
and is covered by the strncmp.
-- 12/09/1999 hobbs
welch Closed ticket [218965ffff].
[History diff]2000-10-26 08:32:16
Log in (anonymous is fine) to add a comment.