Skip to content
Tcl Source Code History Of Ticket 89de498973
Login

History Of Ticket 89de498973

Artifacts Associated With Ticket 89de498973

  1. Ticket change [0754c669e5] (rid 198121) by chrstphrchvz on 2022-02-15 11:12:53:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. 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.
      
    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: "11. Conversions from String"
    14. title initialized to: "signed integer overflow in TclParseNumber()"
    15. type initialized to: "Patch"
  2. Add attachment "tpn-sif.diff" [f11b6ea10f] (rid 198122) by chrstphrchvz on 2022-02-15 11:14:03.

  3. Ticket change [3cd87a8fe5] (rid 198171) by jan.nijtmans on 2022-02-16 15:18:58:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459627.13818025"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed [c5cded8dc704a0cf|here]
      
      Thanks for the report!
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"