Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

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

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. 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
    
  4. foundin changed to: "obsolete: 8.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to:
    Simple conceptual error in code for Tcl_GetIndexFromObjStruc
    
  11. type changed to: "Bug"