Overview
| Artifact ID: | 89fda8167c2d582fcbbee6e20976bb036a8debf9 |
|---|---|
| Ticket: | cafef7c5856ec8b1cbc0ea13c6c41d96d9982d75
Unexplained code in StringRplcCmd function (tclCmdMZ.c) |
| User & Date: | aku on 2015-02-18 21:55:51 |
Changes
- icomment:
First, Tcl_Obj are our structures to hold any value. We are using a model where each value has two representations (string, and internal), and at least one of them is valid at all times, sometimes both. The internal rep (intrep) is a cache, to help with performance. Let us assume that objv[1] == objv[2] == foo when going into the function. The Tcl_GetUnicodeFromObj() [TGUFO] will look at this foo and return a unicode intrep. If the object had a different intrep, or none, this will be computed from the string rep. Then we reach Tcl_GetIntGorIndex() [TGIGI]. While that nominally operates on objv[2] see our assumption above, that it is the same foo the TGUFO operated on. The TGIGI will now throw away the unicode intrep of foo and compute the index intrep. The "ustring" pointer now refers to invalid memory. Trying to use it will crash the interpreter. So the information has to be recomputed with a second TGUFO call. If the assumption was not true then this second calls sees the unicode intrep generated by the first and simply returns it, no calculations done, therefore fast. Is it possible to make the assumption true ? Yes: string replace $start $start $end I.e. use the index in $start and operate on the string for that same number. While contrived it can happen, even if only through a mistake. So we have to guard ourselves against the situation.
- login: "aku"
- mimetype: "text/plain"