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
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- 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.
- foundin changed to: "core-8-6-branch"
- is_private changed to: "0"
- login: "chrstphrchvz"
- priority changed to: "5 Medium"
- private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "chrstphrchvz"
- subsystem changed to: "16. Commands A-H"
- title changed to:
ClockGetdatefieldsObjCmd(): avoid signed integer overflow and platform-dependent behavior
- type changed to: "Patch"