Skip to content
Tcl Source Code History Of Ticket 1c7f179710
Login

History Of Ticket 1c7f179710

Artifacts Associated With Ticket 1c7f179710

  1. Ticket change [4193cd7082] (rid 198315) by chrstphrchvz on 2022-02-18 03:43:30:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. 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) &lt;&lt; (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 &#91;<tt>WIDE_MIN</tt>,<tt>LONG_MIN</tt>) &cup; (<tt>LONG_MAX</tt>,<tt>WIDE_MAX</tt>&#93;); the test suite does not contain an affected example):
      
      <blockquote><pre>
      % ::tcl::mathop::&lt;&lt; -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.
      
    5. foundin initialized to: "core-8-6-branch"
    6. is_private initialized to: "0"
    7. login: "chrstphrchvz"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "chrstphrchvz"
    13. subsystem initialized to: "48. Number Handling"
    14. title initialized to:
      undefined behavior for INST_LSHIFT in ExecuteExtendedBinaryMathOp()
      
    15. type initialized to: "Patch"
  2. Add attachment "1c7f179710.diff" [d3713ecc8b] (rid 198316) by chrstphrchvz on 2022-02-18 04:07:05.

  3. Ticket change [5345740efb] (rid 198879) by jan.nijtmans on 2022-03-08 15:32:38:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459647.14766869"
    3. closer changed to: "jan.nijtmans"
    4. icomment: "Fixed [8a68239de9dfc6ce|here]. Thanks!"
    5. login: "jan.nijtmans"
    6. mimetype: "text/plain"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"