Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 129332b7601e93e96df5c5c67368910ffc5e1817f63c307ba12be0bb48d4ca17
Ticket: 00655c867eabd57ac3acd93bffe2f93799c12c89
ClockGetdatefieldsObjCmd(): avoid signed integer overflow and platform-dependent behavior
User & Date: chrstphrchvz on 2023-05-09 21:05:40
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    clock-61.3 triggers an <tt>-fsanitize=signed-integer-overflow</tt> error:
    <pre>
    generic/tclClock.c:472:52: runtime error: signed integer overflow: 9223372036854775807 + 210866803200 cannot be represented in type 'long long'
    </pre>
    
    See attached patch. To avoid the overflow, I suggest dividing by <tt>SECONDS_PER_DAY</tt> first and then adding <tt>JULIAN_DAY_POSIX_EPOCH</tt> instead. The quotient also needs to be consistently rounded down, rather truncated towards 0 (GNU C and C99) or however a particular platform chooses (C89); otherwise incorrect results are produced for time values prior to the POSIX epoch. Not rounding down already produces incorrect results for time values prior to Julian day 0; the proposed clock-7.10 test currently fails with 
    <pre>-210866803200 -210866889600 -1 -210866803201 0 -210866803200 0 0 0</pre>
     when integer division truncates toward 0.
    
  5. foundin changed to: "core-8-6-branch"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "chrstphrchvz"
  14. subsystem changed to: "16. Commands A-H"
  15. title changed to:
    ClockGetdatefieldsObjCmd(): avoid signed integer overflow and platform-dependent behavior
    
  16. type changed to: "Patch"