Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: aa8746b9b5b5e495fd15c74febfa1dda61e63390
Ticket: 0b39decc764e1af1eaf27b1a289ae4c5822e069e
clock.test 50.2 fails for negative values in IRIX: broken mktime()
User & Date: dexter1 on 2017-01-11 22:48:53
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    Challenge S server R4400 MIPS processor running IRIX 6.5.22m
    Built from 8.6.6 source with MIPSPro compiler 7.4.4 with vendor-patches applied.
    
    'make test' fails with:
    
    ==== clock-50.2 format / scan -2 as a local time FAILED
    ==== Contents of test case:
    
        if {[catch {
            clock scan  [clock format -2 -format %Y%m%d%H%M%S -timezone :localtime] 
     -format %Y%m%d%H%M%S -timezone :localtime
        } result]} {
            if { [regexp " too large" $result] } {
                set result -2
            }
        }
        set result
    
    ---- Result was:
    -1
    ---- Result should have been (exact matching):
    -2
    ==== clock-50.2 FAILED
    
    This happens only when time conversions are issued with '-timezone :localtime' option in the 'clock scan' command. Omitting this option or substituting it with '-timezone :Europe/Amsterdam' will produce the correct result. This is because the mktime() routine is called only when :localtime is issued, in tclClock.c:899 to be exact.
    
    For completeness, in tcl this program shows the bug (expected -2, received -1):
    
    set c [clock format -2 -format %Y%m%d%H%M%S -timezone :localtime]
    puts [clock scan $c -format %Y%m%d%H%M%S -timezone :localtime]
    
    produces:
    
    cyane:~/tcltest> ../src/tcl8.6.6/unix/tcltest clock.tcl 
    -1
    
    IRIX libc function mktime() is old and breaks for pre-1970 tm structs: It will return -1 for all values before the epoch.
    On the other hand, localtime() accepts negative seconds and yields pre-epoch tm structs, so a conversion and back conversion yield different results for negative seconds. This test program demonstrates it:
    
    #include <stdio.h>
    #include <time.h>
    
    int main ()
    {
       time_t endseconds, startseconds = -2;
       endseconds = mktime( localtime( &startseconds ) );
       
       printf("conversion of seconds %d via localtime and mktime is %d\n",startsecon
    ds, endseconds);
    
       return(0);
    }
    
    produces:
    
    conversion of seconds -2 via localtime and mktime is -1
    
    I have substituted the mktime() function in IRIX libc with a mktime.c implementation pulled from netBSD source archive and this fixes the result in the C-example program.
    
    Adding a working mktime.c code in compat/ for IRIX builds with MIPSPro could work, or maybe re-route timezone calls with :localtime to a different function for IRIX.
    
  5. foundin changed to: "8.6.6"
  6. is_private changed to: "0"
  7. login: "dexter1"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "f6a32afcad2bdbc0e0c91beb6d44f2ddf022a09d"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "dexter1"
  14. subsystem changed to: "06. Time Measurement"
  15. title changed to:
    clock.test 50.2 fails for negative values in IRIX: broken mktime()
    
  16. type changed to: "Bug"