Overview
| Artifact ID: | fc5dded1d41a74d93edbc6d3717c722ead9b7b07 |
|---|---|
| Ticket: | 219082ffffffffffffffffffffffffffffffffff
Simple conceptual error in code for Tcl_GetIndexFromObjStruc |
| User & Date: | nobody on 2000-10-26 01:10:25 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
OriginalBugID: 5153 Bug Version: 8.3 SubmitDate: '2000-04-18' LastModified: '2000-06-03' Severity: SER Status: Released Submitter: techsupp ChangedBy: hobbs OS: Linux FixedDate: '2000-06-03' FixedInVersion: 8.4a1 ClosedDate: '2000-10-25' Name: Eric Perkins CVS: RCS: @(#) $Id: tclIndexObj.c,v 1.4 1999/06/28 23:49:31 redman Exp $ CustomShell: none Comments: the patch works as far as i've tested it. ReproducibleScript: //The following command is created in the interpreter and called with the syntax: // "mycommand key2" int mycommand(ClientData, Tcl_Interp * interp, int objc, Tcl_Obj * const objv[]) { typedef struct {char * key; ClientData d1; ClientData d2} MyStruct; MyStruct table[] = { {"key1",1,2}, {"key2",3,4}, {"key3",5,6} }; int index; int rv = Tcl_GetIndexFromObjStruct(interp,objv[1],(char**)table,sizeof(MyStruct),"option",0,&index); Tcl_WrongNumArgs(interp,2,obvj," rest of args"); return TCL_OK; } ObservedBehavior: segv during Tcl_WrongNumArgs The reason: the of the object for the first argument gets set to &table[0].key as it should, but the internalRep.twoPtrValue.ptr2 gets set to 1 (the number ofsets away from the beginning) when the string is retrieved from the table in Tcl_WrongNumArgs, the following expression is used: tablePtr[(int) objv[i]->internalRep.twoPtrValue.ptr2] which evaluates to ((char **)table)[1] which is, of course table[0].d1 and not table[1].key the internalRep.twoPtrValue.ptr2 should instead get set to (index * offset/sizeof(char*)), in this case, index*3 = 3. which evaluates correctly as ((char**)table)[3] = table[1].key DesiredBehavior: see above Patch: *** /home/edp/p1-edp/in/tcl8.3.0/generic/tclIndexObj.c Mon Jun 28 19:49:31 1999 --- tclIndexObj.c Tue Apr 18 14:59:59 2000 *************** *** 213,219 **** objPtr->typePtr->freeIntRepProc(objPtr); } objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tablePtr; ! objPtr->internalRep.twoPtrValue.ptr2 = (VOID *) index; objPtr->typePtr = &tclIndexType; *indexPtr = index; return TCL_OK; --- 213,219 ---- objPtr->typePtr->freeIntRepProc(objPtr); } objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tablePtr; ! objPtr->internalRep.twoPtrValue.ptr2 = (VOID *) (index*offset/sizeof(char*)); objPtr->typePtr = &tclIndexType; *indexPtr = index; return TCL_OK; PatchFiles: tclIndexObj.c Verified and patched for 8.4a1. -- 06/03/2000 hobbs - foundin changed to: "obsolete: 8.3"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "69. Other"
- title changed to:
Simple conceptual error in code for Tcl_GetIndexFromObjStruc
- type changed to: "Bug"