<i>Unexplained code in StringRplcCmd function (tclCmdMZ.c)</i> status still Open with 3 other changes
by
.
D 2015-02-18T21:55:51.925
J icomment First,\sTcl_Obj\sare\sour\sstructures\sto\shold\sany\svalue.\r\nWe\sare\susing\sa\smodel\swhere\seach\svalue\shas\stwo\srepresentations\r\n(string,\sand\sinternal),\sand\sat\sleast\sone\sof\sthem\sis\svalid\sat\sall\stimes,\ssometimes\sboth.\sThe\sinternal\srep\s(intrep)\sis\sa\scache,\sto\shelp\swith\sperformance.\r\n\r\nLet\sus\sassume\sthat\s\r\n\r\n\s\s\sobjv[1]\s==\sobjv[2]\s==\sfoo\r\n\r\nwhen\sgoing\sinto\sthe\sfunction.\r\n\r\nThe\sTcl_GetUnicodeFromObj()\s[TGUFO]\swill\slook\sat\sthis\sfoo\sand\sreturn\sa\sunicode\sintrep.\r\nIf\sthe\sobject\shad\sa\sdifferent\sintrep,\sor\snone,\sthis\swill\sbe\scomputed\sfrom\sthe\sstring\srep.\r\n\r\nThen\swe\sreach\sTcl_GetIntGorIndex()\s[TGIGI].\sWhile\sthat\snominally\soperates\son\sobjv[2]\ssee\sour\sassumption\sabove,\sthat\sit\sis\sthe\ssame\sfoo\sthe\sTGUFO\soperated\son.\r\n\r\nThe\sTGIGI\swill\snow\sthrow\saway\sthe\sunicode\sintrep\sof\sfoo\sand\scompute\sthe\sindex\sintrep.\r\n\r\nThe\s"ustring"\spointer\snow\srefers\sto\sinvalid\smemory.\r\nTrying\sto\suse\sit\swill\scrash\sthe\sinterpreter.\r\n\r\nSo\sthe\sinformation\shas\sto\sbe\srecomputed\swith\sa\ssecond\sTGUFO\scall.\r\nIf\sthe\sassumption\swas\snot\strue\sthen\sthis\ssecond\scalls\ssees\sthe\sunicode\sintrep\sgenerated\sby\sthe\sfirst\sand\ssimply\sreturns\sit,\sno\scalculations\sdone,\stherefore\sfast.\r\n\r\nIs\sit\spossible\sto\smake\sthe\sassumption\strue\s?\r\nYes:\r\n\s\s\sstring\sreplace\s$start\s$start\s$end\r\n\r\nI.e.\suse\sthe\sindex\sin\s$start\sand\soperate\son\sthe\sstring\sfor\sthat\ssame\snumber.\r\nWhile\scontrived\sit\scan\shappen,\seven\sif\sonly\sthrough\sa\smistake.\r\nSo\swe\shave\sto\sguard\sourselves\sagainst\sthe\ssituation.
J login aku
J mimetype text/plain
K cafef7c5856ec8b1cbc0ea13c6c41d96d9982d75
U aku
Z 710c18a3654de23dbc4f9b56b22c1d70