Artifacts Associated With Ticket 1c7f179710
Ticket change [4193cd7082] (rid 198315) by chrstphrchvz on 2022-02-18 03:43:30:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
Analogous to [b0f84119c8] for left-shifting a value represented by a <tt>Tcl_WideInt</tt> (and not a <tt>long</tt> or a bignum) when <tt>Tcl_WideInt</tt> is <tt>long long</tt> (because <tt>long</tt> is only 32-bit): <ul><li>Left-shifting by 0 causes signed integer overflow (undefined behavior detected by UBSan <tt>-fsanitize=shift-base</tt>) in the expression: <blockquote><pre> ((Tcl_WideInt)1) << (CHAR_BIT*sizeof(Tcl_WideInt) - 1 - shift) </pre></blockquote> i.e. 1 is shifted left (64-1-0)=63 times, which overflows; and signed integer overflow (undefined behavior detected by UBSan <tt>-fsanitize=signed-integer-overflow</tt>) when the overflowed result <tt>WIDE_MIN</tt> of the above expression is negated.</li> <li>If the left-shifted value is negative, then there is left-shifting of a negative value (undefined behavior detected by UBSan <tt>-fsanitize=shift-base</tt>).</li></ul> Example command (left operand is in the range [<tt>WIDE_MIN</tt>,<tt>LONG_MIN</tt>) ∪ (<tt>LONG_MAX</tt>,<tt>WIDE_MAX</tt>]); the test suite does not contain an affected example): <blockquote><pre> % ::tcl::mathop::<< -0x80000001 0 <span style="font-weight: bold">tcl/generic/tclExecute.c:8665:4:<span style="color:firebrick"> runtime error:</span> left shift of 1 by 63 places cannot be represented in type 'long long int'</span> <span style="font-weight: bold">tcl/generic/tclExecute.c:8664:6:<span style="color:firebrick"> 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> <span style="font-weight: bold">tcl/generic/tclExecute.c:8666:7:<span style="color:firebrick"> runtime error: </span>left shift of negative value -2147483649</span> -2147483649 </pre></blockquote> The attached patch avoids this by casting to <tt>Tcl_WideUInt</tt> in a couple of places before shifting. - 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: "48. Number Handling"
- title initialized to:
undefined behavior for INST_LSHIFT in ExecuteExtendedBinaryMathOp()
- type initialized to: "Patch"
Add attachment "1c7f179710.diff" [d3713ecc8b] (rid 198316) by chrstphrchvz on 2022-02-18 04:07:05.
Ticket change [5345740efb] (rid 198879) by jan.nijtmans on 2022-03-08 15:32:38:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459647.14766869"
- closer changed to: "jan.nijtmans"
- icomment: "Fixed [8a68239de9dfc6ce|here]. Thanks!"
- login: "jan.nijtmans"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"