Skip to content
Tcl Source Code Artifact [2121dfbc37]
Login

Artifact [2121dfbc37]

Artifact 2121dfbc375793b34deaaf510b72d2dc29d3dfb4:

Ticket change [2121dfbc37] - New ticket [2089279fffffffff|2089279fff] <i>StringObj.3 Tcl_ObjPrintf inaccuracies</i>. by georgeps on 2008-09-02 16:27:27.
D 2008-09-02T16:27:27
J assignee hobbs
J cmimetype text/plain
J comment StringObj.3\sgives\sthis\sexample:\nlong\sx\s=\s5;\nTcl_Obj\s*objPtr\s=\sTcl_ObjPrintf("Value\sis\s%d",\sx);\n\nThis\sis\sincorrect,\sbecause\sthe\sTcl_ObjPrintf\scode\swill\sexpect\san\sint,\sand\suse\sva_arg\swith\sint.\n\nAs\scan\sbe\sseen\sin\sthe\sAppendPrintfToObjVA:\n\scase\s'd':\n\s\s\s...\n\s\s\sseekingConversion\s=\s0;\n\s\s\sswitch\s(size)\s{\n\s\s\s\s\s\scase\s-1:\n\s\s\s\s\s\scase\s0:\n\s\s\s\s\s\s\s\sTcl_ListObjAppendElement(NULL,\slist,\sTcl_NewLongObj((long\sint)va_arg(argList,\sint)));\n\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.\n\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.\n\nThe\snext\sissue\sis\sthat\sthe\sformat\sspecifiers\sare\snot\sexactly\sthe\ssame\sas\sthe\s[format]\scommand,\sand\sprobably\sshouldn't\sbe.\n\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.\n
J foundin obsolete:\s8.6a2
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter georgeps
J subsystem 55.\sOther\sTools
J title StringObj.3\sTcl_ObjPrintf\sinaccuracies
J type Bug
K 2089279fffffffffffffffffffffffffffffffff
U georgeps
Z 5d37ce1afdc7db276c9f7cd1368ad133