Overview
| Artifact ID: | c6632dc898c9aae70d083892ccf0aa906925c863 |
|---|---|
| Ticket: | 494348ffffffffffffffffffffffffffffffffff
foreach crashes in recursion |
| User & Date: | nobody on 2001-12-17 22:06:29 |
Changes
- assignee changed to: "dkf"
- cmimetype changed to: "text/plain"
- comment changed to:
- Tcl Version: 8.x+; - OS: Solaris 5.x (Any); - Compiler: Sun CC 6.0 Upd 1; - Problem behavior: Tcl may freely convert the type of objects. Foreach command stores the pointers to objects of loop variables at the begin of the loop: for (i = 0; i < numLists; i++) { result = Tcl_ListObjGetElements(interp, argObjv[1+i*2], &varcList[i], &varvList[i]); -> Var list is in varvList. Later it only checks if the variable list object has the list type: if (argObjv[1+i*2]->typePtr != &tclListType) result = Tcl_ListObjGetElements(interp, argObjv[1+i*2], -> conditionally recreates the list and if the type is "list", it considers the list correct. Now suppose the loop body calls the function with the same name as the loop variable. This will convert the var list object to "cmdName" type and lose the pointers to all loop variable objects. Then, in recursion, we wil recreate the var list conversting "cmdName" to "list". After return from recursion to the first loop we will have the correct list but with another objects. After checking the type of var list object (it is "list" now) we'll continue to use stored pointers (varvlist) and will crash on the second iteration. You will not crash if nobody used that freed memory, but it does not change anything. It's a real critical bug for us. To fix it I made the second list parsing (Tcl_ListObjGetElements) unconditional. Short testcase (I know it might be shorter): -------------- proc inst {args} { } proc Something {} { inst } proc Test {level} { incr level puts "Test: level = $level" #inst "a" Something ;# you may call inst directly if {$level == 1} { set instlist {1 2} } else { set instlist {} } puts "instlist = /$instlist/" foreach inst $instlist { puts "inst = /$inst/" Test $level } } Test 0 -------------------- Regards, Yevgen Ryazanov - 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: "16. Commands A-H"
- title changed to: "foreach crashes in recursion"
- type changed to: "Bug"