Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-18
22:29 • Ticket [218873ffff] Bug in TclRegisterLiteral() status still Closed with 3 o... artifact: c7cdbf9665 user: dgp
2000-10-26
08:30 • Closed ticket [218873ffff]. artifact: 0f0f90c72c user: welch
01:07 • New ticket [218873ffff]. artifact: 0dffcb3887 user: nobody

Bug in TclRegisterLiteral()

Closed / Fixed218873ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:07:01
OriginalBugID: 2496 Bug
Version: 8.2b1
SubmitDate: '1999-08-04'
LastModified: '1999-08-04'
Severity: LOW
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Other
Machine: NA
FixedDate: '1999-08-04'
FixedInVersion: 8.2
ClosedDate: '2000-10-25'


Name:
Peter Spjuth

ObservedBehavior:
In tclLiteral.c, line 271, in the function TclRegisterLiteral,
    the following can be found:
    
    if (TclLooksLikeInt(bytes, length)) {
        if (TclGetLong((Tcl_Interp *) NULL, bytes, &n) == TCL_OK) {
    TclFormatInt(buf, n);
    if (strcmp(bytes, buf) == 0) {
        objPtr->internalRep.longValue = n;
        objPtr->typePtr = &tclIntType;
    }
        }
    }
    
    This is supposed to detect integer literals and give them an
    integer internal representation from the start.
    In reality though, it don't seem to work.
    
    What I believe is a bug is using "bytes" in the calls to
    TclGetLong and strcmp, since the literal at "bytes" is not null
    terminated. Typically, "bytes" is within a string being parsed,
    making it important to always use "length".
    On the code lines above these, the literal string is copied to
    "objPtr" and, as far as I can see, the resulting string in
    "objPtr" becomes properly null terminated.
    Thus, using "objPtr->bytes" instead of "bytes" in those two calls
    feels like a better solution.
    
    I haven't found any way to detect this bug using standard Tcl.
    I have a thing called "info internalrep" which gives the
    internal representation for an object. I found it odd that
    "info internalrep 4" returned "int" and "info internalrep 5"
    did not, and that put me on the track for this bug.
    
    I have not made any patch for this, since I currently can't test it.



This change has been made for 8.2b3 (GetLong and strcmp calls
use the objPtr->bytes). 
-- 08/04/1999 hobbs
welch Closed ticket [218873ffff]. [History diff]2000-10-26 08:30:15
dgp Ticket [218873ffff]: 3 changes [History diff]2001-04-18 22:29:00
Log in (anonymous is fine) to add a comment.