Artifacts Associated With Ticket 89de498973
Ticket change [0754c669e5] (rid 198121) by chrstphrchvz on 2022-02-15 11:12:53:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
Signed integer overflow (undefined behavior) occurs in <tt>TclParseNumber()</tt> (tclStrToD.c) for inputs equal to <tt>LONG_MIN</tt> or <tt>LLONG_MIN</tt>. UBSan (<tt>-fsanitize=signed-integer-overflow</tt>) errors for 32-bit <tt>long</tt> and 64-bit <tt>long long</tt>: <blockquote><pre> % set a 0; incr a -0o1000000000000000000000 <span style="font-weight:bold">tcl/generic/tclStrToD.c:1315:9:<span style="color:red"> runtime error: </span>negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself</span> -9223372036854775808 % set b 0; incr b -0o20000000000 <span style="font-weight:bold">tcl/generic/tclStrToD.c:1330:5:<span style="color:red"> runtime error: </span>negation of -2147483648 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself</span> -2147483648 % set c 0; incr c -0x8000000000000000 <span style="font-weight:bold">tcl/generic/tclStrToD.c:1362:9:<span style="color:red"> runtime error: </span>negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself</span> -9223372036854775808 % set d 0; incr d -0x80000000 <span style="font-weight:bold">tcl/generic/tclStrToD.c:1377:5:<span style="color:red"> runtime error: </span>negation of -2147483648 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself</span> -2147483648 </pre></blockquote> Negating before casting avoids this. However it may also be preferable to negate by subtracting from 0 (binary minus) to avoid compiler warnings for unary minus with unsigned operand (e.g. [https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146|MSVC <tt>/W2</tt> warning C4146]). See attached patch.
- foundin initialized to: "core-8-6-branch"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "11. Conversions from String"
- title initialized to: "signed integer overflow in TclParseNumber()"
- type initialized to: "Patch"
Add attachment "tpn-sif.diff" [f11b6ea10f] (rid 198122) by chrstphrchvz on 2022-02-15 11:14:03.
Ticket change [3cd87a8fe5] (rid 198171) by jan.nijtmans on 2022-02-16 15:18:58:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459627.13818025"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed [c5cded8dc704a0cf|here] Thanks for the report!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"