Skip to content
Tcl Source Code Artifact [0754c669e5]
Login

Artifact [0754c669e5]

Artifact 0754c669e5848f2a7d30b338b6b1b5c595b70f9a2404cde7ab043c9510fd46a2:

Ticket change [0754c669e5] - New ticket [89de4989734eb772|89de498973] <i>signed integer overflow in TclParseNumber()</i>. by chrstphrchvz on 2022-02-15 11:12:53.
D 2022-02-15T11:12:53.355
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment Signed\sinteger\soverflow\s(undefined\sbehavior)\soccurs\sin\s<tt>TclParseNumber()</tt>\s(tclStrToD.c)\sfor\sinputs\sequal\sto\s<tt>LONG_MIN</tt>\sor\s<tt>LLONG_MIN</tt>.\sUBSan\s(<tt>-fsanitize=signed-integer-overflow</tt>)\serrors\sfor\s32-bit\s<tt>long</tt>\sand\s64-bit\s<tt>long\slong</tt>:\r\n\r\n<blockquote><pre>\r\n%\sset\sa\s0;\sincr\sa\s-0o1000000000000000000000\r\n<span\sstyle="font-weight:bold">tcl/generic/tclStrToD.c:1315:9:<span\sstyle="color:red">\sruntime\serror:\s</span>negation\sof\s-9223372036854775808\scannot\sbe\srepresented\sin\stype\s'long\slong\sint';\scast\sto\san\sunsigned\stype\sto\snegate\sthis\svalue\sto\sitself</span>\r\n-9223372036854775808\r\n%\sset\sb\s0;\sincr\sb\s-0o20000000000\r\n<span\sstyle="font-weight:bold">tcl/generic/tclStrToD.c:1330:5:<span\sstyle="color:red">\sruntime\serror:\s</span>negation\sof\s-2147483648\scannot\sbe\srepresented\sin\stype\s'long\sint';\scast\sto\san\sunsigned\stype\sto\snegate\sthis\svalue\sto\sitself</span>\r\n-2147483648\r\n%\sset\sc\s0;\sincr\sc\s-0x8000000000000000\r\n<span\sstyle="font-weight:bold">tcl/generic/tclStrToD.c:1362:9:<span\sstyle="color:red">\sruntime\serror:\s</span>negation\sof\s-9223372036854775808\scannot\sbe\srepresented\sin\stype\s'long\slong\sint';\scast\sto\san\sunsigned\stype\sto\snegate\sthis\svalue\sto\sitself</span>\r\n-9223372036854775808\r\n%\sset\sd\s0;\sincr\sd\s-0x80000000\r\n<span\sstyle="font-weight:bold">tcl/generic/tclStrToD.c:1377:5:<span\sstyle="color:red">\sruntime\serror:\s</span>negation\sof\s-2147483648\scannot\sbe\srepresented\sin\stype\s'long\sint';\scast\sto\san\sunsigned\stype\sto\snegate\sthis\svalue\sto\sitself</span>\r\n-2147483648\r\n</pre></blockquote>\r\n\r\nNegating\sbefore\scasting\savoids\sthis.\sHowever\sit\smay\salso\sbe\spreferable\sto\snegate\sby\ssubtracting\sfrom\s0\s(binary\sminus)\sto\savoid\scompiler\swarnings\sfor\sunary\sminus\swith\sunsigned\soperand\s(e.g.\s[https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146|MSVC\s<tt>/W2</tt>\swarning\sC4146]).\sSee\sattached\spatch.
J foundin core-8-6-branch
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 11.\sConversions\sfrom\sString
J title signed\sinteger\soverflow\sin\sTclParseNumber()
J type Patch
K 89de4989734eb7720a8e7308e848b46e2f72f972
U chrstphrchvz
Z 6876e8f897a3054c5da4e161de774c54