http://d.puremagic.com/issues/show_bug.cgi?id=5262

           Summary: divide by 0 in std.datetime's Ticks.toMicroseconds()
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: bra...@puremagic.com


--- Comment #0 from Brad Roberts <bra...@puremagic.com> 2010-11-23 16:08:41 PST 
---
fedora 12 (ami-0d638d64 running on an ec2 t1.micro in case it matters), running
the phobos unit tests I'm getting a fp exception.  This is a 64 bit box, 32 bit
build of dmd, druntime, and phobos.

Inside the static ctor for struct Ticks, it's hitting the true code path of the
static if and false path of if clock_getres():

    ticksPerSec = 1000_000_000 / ts.tv_nsec;

ts.tv_nsec=999848 which results in ticksPerSec=1000.

Later, when this code runs:
    const
    T toMicroseconds(T)() if (isIntegral!T && T.sizeof >= 4)
    {  
        return value/(ticksPerSec/1000/1000);
    }

ticksPerSec/1000/1000 --> 0

called from here:
285         unittest
286         {
287             auto t = Ticks.fromMicroseconds(1000000);
288             assert(t.usec == 1000000); // <--- here

On the auto-testers, running ubuntu, it takes the false path of that static if
and just directly assigns ticksPerSec to 1M which survives the /1000/1000 as 1.

The full stack:
(gdb) bt
#0  0x0808490c in __ULDIV__ ()
#1  0x0807a952 in std.datetime.Ticks.toMicroseconds!(long).toMicroseconds
(this=0xffffd35c) at std/datetime.d:248
#2  0x0807a31c in std.datetime.Ticks.__unittest6 () at std/datetime.d:284
#3  0x0807bba0 in _D3std8datetime9__modtestFZv ()
#4  0x08080d5c in
_D4core7runtime18runModuleUnitTestsUZb16__foreachbody168MFKPS6object10ModuleInfoZi
()
#5  0x0807dcd2 in _D6object10ModuleInfo7opApplyFMDFKPS6object10ModuleInfoZiZi
()
#6  0x08080c77 in runModuleUnitTests ()
#7  0x0807e448 in _D2rt6dmain24mainUiPPaZi6runAllMFZv ()
#8  0x0807e370 in _D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv ()
#9  0x0807e316 in main ()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to