Tcl Source Code

Artifact [0d3171c42f]
Login

Artifact 0d3171c42f1ff28b3ba3b98967e4e04bbfbec707:

Ticket change [0d3171c42f] - Ticket [2089279fff] StringObj.3 Tcl_ObjPrintf inaccuracies status still Open with 6 other changes by stu 2017-07-08 18:37:03.
D 2017-07-08T18:37:03.764
J closer nobody
J comment StringObj.3\sgives\sthis\sexample:\r\nlong\sx\s=\s5;\r\nTcl_Obj\s*objPtr\s=\sTcl_ObjPrintf("Value\sis\s%d",\sx);\r\n\r\nThis\sis\sincorrect,\sbecause\sthe\sTcl_ObjPrintf\scode\swill\sexpect\san\sint,\sand\suse\sva_arg\swith\sint.\r\n\r\nAs\scan\sbe\sseen\sin\sthe\sAppendPrintfToObjVA:\r\n\scase\s'd':\r\n\s\s\s...\r\n\s\s\sseekingConversion\s=\s0;\r\n\s\s\sswitch\s(size)\s{\r\n\s\s\s\s\s\scase\s-1:\r\n\s\s\s\s\s\scase\s0:\r\n\s\s\s\s\s\s\s\sTcl_ListObjAppendElement(NULL,\slist,\sTcl_NewLongObj((long\sint)va_arg(argList,\sint)));\r\n\r\nThe\sissue\sis\sthat\sif\sthe\suser\suses\s%d\sfor\sa\slong,\sthe\sva_list\swill\shave\sthe\swrong\soffset.\s\sThe\sexample\swill\swork\sin\sthe\s1\sargument\scase,\sand\seven\sthe\smultiple\sargument\scase\sif\ssizeof(int)\s=\ssizeof(long).\s\sIt\showever\swill\sfail\sin\sthe\scase\sof\ssizeof(long)\s>\ssizeof(int),\sbecause\sthe\sva_list\swill\shave\sthe\swrong\soffset.\s\sThus\syou'd\sbe\sgetting\sparts\sof\sthe\sinteger.\s\sThis\scan\shave\sdisasterous\sconsequences\sif\sthe\soffset\sis\swrong,\sbecause\sthe\snext\sva_arg\scall\sbecomes\swrong,\swhich\sif\sit's\sa\spointer\smay\slead\sto\ssegfaults.\r\n\r\nTcl\sworks\swith\ssome\splatforms\swhere\sa\slong\sis\s64-bit\sand\san\sint\sis\s32-bit.\s\s#ifdef\sTCL_WIDE_INT_IS_LONG\sas\sI\sunderstand\sit\srefers\sto\sthis.\r\n\r\nThe\snext\sissue\sis\sthat\sthe\sformat\sspecifiers\sare\snot\sexactly\sthe\ssame\sas\sthe\s[format]\scommand,\sand\sprobably\sshouldn't\sbe.\r\n\r\nThe\sformat\scommand\suses\s(as\sdocumented)\s%ld\sfor\struncation\sto\sa\s64-bit\sinteger.\s\s%lld\sfor\sno\struncation\s(BigNum)\sand\s%d\sfor\sa\s32-bit\sinteger.\s\sThis\sis\sincomptible\swith\sAppendPrintfToObjVA()\s(used\sby\sTcl_ObjPrintf),\sbecause\sit\scurrently\saccepts\sa\slong\sfor\s%ld\swhich\smay\sor\smay\snot\sbe\s64-bit\sdepending\son\sthe\splatform.\s\sThe\swide\sand\sBigNum\scases\sare\salso\snot\shandled\sby\sAppendPrintfToObjVA().\s\sThus\sthe\ssuggestion\sin\sthe\sdocumentation\sthat\sTcl_ObjPrintf\shas\sthe\ssame\ssyntax\sas\sthe\sformat\scommand\sare\swrong.
J icomment Just\sstumbled\sacross\sthis.\r\nSee\salso\shttp://core.tcl.tk/tcl/tktview/2b6a4fa5ed30b44364b1\r\n\r\nOn\s32-bit\ssystems:\r\n\r\nTcl_ObjPrintf("%lld\s%ld\\n",\s(long\slong)\s3,\s(long)\s4))\r\nYields\s"3\s0"\r\n\r\nTcl_ObjPrintf("%lld\s%s\\n",\s(long\slong)\s3,\s"a"))\r\nSegfaults\r\n\r\n\r\nRight\snow\sit's\shard\sto\shave\sconfidence\sin\sTcl_ObjPrintf.\r\nEven\sif\sit\swas\sfixed\stoday\sthe\sbroken\sversion\swill\spersist\sin\sthe\swild\sfor\sa\slong\stime\spossibly\srequiring\sautoconfery\sfor\sthose\swho\swish\sto\suse\sit\swith\sconfidence.\r\n\r\nToo\sbad.
J login stu
J mimetype text/plain
J severity Minor
K 2089279fffffffffffffffffffffffffffffffff
U stu
Z 97241440f61377e5e1211cfaab78b599