Skip to content
Tcl Source Code History Of Ticket 00655c867e
Login

History Of Ticket 00655c867e

Artifacts Associated With Ticket 00655c867e

  1. Ticket change [129332b760] (rid 214767) by chrstphrchvz on 2023-05-09 21:05:40:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized 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 initialized to: "core-8-6-branch"
    6. is_private initialized to: "0"
    7. login: "chrstphrchvz"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "chrstphrchvz"
    14. subsystem initialized to: "16. Commands A-H"
    15. title initialized to:
      ClockGetdatefieldsObjCmd(): avoid signed integer overflow and platform-dependent behavior
      
    16. type initialized to: "Patch"
  2. Add attachment "00655c867eab.diff" [e83aa4bc3e] (rid 214769) by chrstphrchvz on 2023-05-09 21:16:27.

  3. Ticket change [9823740c38] (rid 218205) by jan.nijtmans on 2023-09-14 21:19:34:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2460202.38858978"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed [ee677ecc84710dfd|here].
      
      Many thanks!
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
  4. Ticket change [45f0f2a9ec] (rid 218522) by jan.nijtmans on 2023-09-20 13:37:47:

    1. closer changed to: "nobody"
    2. icomment:
      
      The new testcase fails in a OPTS=static,msvcrt build in Visual Studio, passes in all other configurations.
      
      <pre>
      clock.test
      
      
      ==== clock-7.10 Julian Day, negative amount FAILED
      ==== Contents of test case:
      
          # Note: %J does not accept negative input;
          # add negative amounts to Julian day 0 instead
          set s0 [clock scan 0 -format %J -gmt true]
          set J0 [scan [clock format $s0 -format %J -gmt true] %lld]
          set s0m1d [clock add $s0 -1 days]
          set s0m24h [clock add $s0 -24 hours]
          set J0m24h [scan [clock format $s0m24h -format %J -gmt true] %lld]
          set s0m1s [clock add $s0 -1 seconds]
          set J0m1s [scan [clock format $s0m1s -format %J -gmt true] %lld]
          list $s0m1d $s0m24h $J0m24h $s0m1s $J0m1s $s0 $J0  [::tcl::mathop::== $s0m1d $s0m24h] [::tcl::mathop::== $J0m24h $J0m1s]
      
      ---- Test generated error; Return code was: 1
      ---- Return code should have been one of: 0 2
      ---- errorInfo: localtime failed (clock value may be too large/small to represent)
          while executing
      "return -options $opts $result"
          (procedure "::tcl::clock::add" line 98)
          invoked from within
      "clock add $s0 -1 days"
          ("uplevel" body line 6)
          invoked from within
      "uplevel 1 $script"
      ---- errorCode: CLOCK localtimeFailed
      ==== clock-7.10 FAILED
      
      cmdAH.test
      </pre>
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
    5. status changed to: "Pending"
  5. Ticket change [2f4268f4a2] (rid 218523) by chrstphrchvz on 2023-09-20 15:12:23:

    1. icomment:
      I have reproduced this locally and will take a look. Note that without the change to tclClock.c the test still fails for the same reason.
      
    2. login: "chrstphrchvz"
    3. mimetype: "text/x-fossil-wiki"
  6. Ticket change [08ac420864] (rid 218530) by jan.nijtmans on 2023-09-20 15:54:28:

    1. icomment:
      Strange also, that all tests in 8.7 pass. Why does this fail in 8.6?
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  7. Ticket change [3503ed3959] (rid 218531) by chrstphrchvz on 2023-09-20 16:57:37:

    1. icomment:
      I notice that <tt>::tcl::clock::GetSystemTimeZone</tt> is returning <tt>:localtime</tt> when running tests for the <tt>OPTS=static,mscvrt</tt> configuration (rather than e.g. <tt>:America/Chicago</tt>), which causes <tt>ConvertUTCToLocal()</tt> to use <tt>ConvertUTCToLocalUsingC()</tt> instead of <tt>ConvertUTCToLocalUsingTable()</tt>. I am guessing this is not intentional.
      
      However I wonder if clock-7.10 should still work with <tt>:localtime</tt>, or be constrained to not run under <tt>:localtime</tt>. Either way, having a similar test which forces <tt>:localtime</tt> could be useful.
      
    2. login: "chrstphrchvz"
    3. mimetype: "text/x-fossil-wiki"
  8. Ticket change [b0422cc405] (rid 218533) by chrstphrchvz on 2023-09-20 20:09:04:

    1. icomment:
      However, the conditions under which <tt>localtime()</tt>/<tt>localtime_r()</tt> encounters errors (e.g. <tt>EOVERFLOW</tt>) are platform-dependent. So a test which uses these functions may not be portable.
      
    2. login: "chrstphrchvz"
    3. mimetype: "text/x-fossil-wiki"
  9. Ticket change [021b0ac236] (rid 218534) by chrstphrchvz on 2023-09-20 20:50:33:

    1. icomment:
      The exact cutoffs for <tt>localtime()</tt>/<tt>localtime_r()</tt> errors may depend on the platform epoch, but if <tt>struct tm</tt> is consistently defined, then I would think time values with years way outside of <tt>&#91;1900+INT_MIN,1900+INT_MAX&#93;</tt> will reliably cause an error. I will likely open other tickets about this.
      
    2. login: "chrstphrchvz"
    3. mimetype: "text/x-fossil-wiki"
  10. Add attachment "clock-7.10-add-utc.diff" [a21a4f2486] (rid 218536) by chrstphrchvz on 2023-09-20 21:59:44.

  11. Ticket change [989d74d3c0] (rid 218537) by chrstphrchvz on 2023-09-20 22:02:46:

    1. 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><span style="color:firebrick">-210866803200</span> -210866889600 -1 -210866803201 <span style="color:firebrick">0</span> -210866803200 0 <span style="color:firebrick">0</span> <span style="color:firebrick">0</span></pre>
       when integer division truncates toward 0.
      
    2. icomment:
      I neglected how <tt>clock add … days</tt> takes <tt>-timezone</tt> into consideration. Specifying <tt>-timezone :UTC</tt> to <tt>clock add … days</tt> avoids the failure on <tt>OPTS=static,msvcrt</tt>, although whether <tt>GetSystemTimeZone</tt> is correct or unexpectedly <tt>:localtime</tt> is beyond the scope of this test. <tt>-timezone</tt> should likely also be specified in the test’s other <tt>clock add</tt> usage for consistency. See attached patch.
      
    3. login: "chrstphrchvz"
    4. mimetype: "text/x-fossil-wiki"
  12. Ticket change [352b13db5d] (rid 218568) by jan.nijtmans on 2023-09-21 11:15:36:

    1. closedate changed to: "2460208.96917304"
    2. closer changed to: "jan.nijtmans"
    3. icomment: "Thanks! Closing now."
    4. login: "jan.nijtmans"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"