Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a7be3a81ab2de6a8e4d89ed5d09194781c4c975bdc8dfa082120593cb71e946c
Ticket: 1c60dca3412236a4992ff57dae575a7df91b65f0
signed integer overflow in Tcl_SetBignumObj()
User & Date: chrstphrchvz on 2022-02-16 00:15:17
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    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 -0x8000000000000001; incr a 1
    <span style="font-weight:bold">tcl/generic/tclObj.c:3576:6:<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 -0x8000000000000001; incr b 0x7fffffff80000001
    <span style="font-weight:bold">tcl/generic/tclObj.c:3550:6:<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>
    
    As with [89de498973], this can be avoided by negating before casting, and 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 changed to: "core-8-6-branch"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "chrstphrchvz"
  13. subsystem changed to: "48. Number Handling"
  14. title changed to: "signed integer overflow in Tcl_SetBignumObj()"
  15. type changed to: "Patch"