.
D 2021-12-24T19:11:02.455
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment In\s<tt>GrowStringBuffer()</tt>\s(generic/tclStringObj.c),\sit\sis\spossible\sfor\s<tt>int\sattempt</tt>\sto\sbe\sassigned\s<tt>INT_MAX</tt>,\ssuch\sas\swhen\sthe\sfunction\sis\scalled\swith\s<tt>int\sneeded\s=\sINT_MAX</tt>.\sWhen\sthis\shappens,\s<tt>int\sattempt</tt>\swill\salso\sbe\sassigned\s<tt>INT_MAX</tt>,\sand\s<tt>attempt\s+\s1</tt>\swill\soverflow\s(although\sI\sdo\snot\sobserve\sthis\scausing\sunexpected\sbehavior).\s[https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks|UBSan\s(<tt>-fsanitize=signed-integer-overflow</tt>)]\serror\sexample:\r\n\r\n<pre>\r\n%\sset\sdz\s[open\s/dev/zero\s[list\sRDONLY]]\r\n%\sset\snulls\s[read\s$dz\s[expr\s{(1\s<<\s30)\s-\s1}]]\r\n<span\sstyle="font-weight:bold">tcl/generic/tclStringObj.c:167:20:\s<span\sstyle="color:red">runtime\serror:</span>\ssigned\sinteger\soverflow:\s2147483647\s+\s1\scannot\sbe\srepresented\sin\stype\s'int'</span>\r\n</pre>\r\n\r\nIf\sit\sis\sindeed\sokay\sto\sallocate\s<tt>(unsigned\sint)INT_MAX\s+\s1U</tt>,\sthen\ssome\spossible\sways\sto\savoid\soverflow\sinclude\sdeclaring\s<tt>attempt</tt>\sas\s<tt>unsigned\sint</tt>,\sor\schanging\sinstances\sof\s<tt>attempt\s+\s1</tt>\sto\spromote\s<tt>attempt</tt>\sto\s<tt>unsigned\sint</tt>\s(such\sas\sby\susing\s<tt>attempt\s+\s1U</tt>).
J foundin 8.6.12
J is_private 0
J login chrstphrchvz
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter chrstphrchvz
J subsystem 10.\sObjects
J title GrowStringBuffer():\ssigned\sinteger\soverflow
J type Bug
K 816913a65eabbd69b07be7221b68b10064103a0e
U chrstphrchvz
Z 742bc1bce985df6c808040f6ec6863c7