Thread overview
[Issue 8369] New: try/finally block and float division by zero
Jul 10, 2012
Artem Tarasov
Dec 31, 2012
SomeDude
Jan 01, 2013
Maxim Fomin
Jan 02, 2013
Maxim Fomin
July 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8369

           Summary: try/finally block and float division by zero
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: lomereiter@gmail.com


--- Comment #0 from Artem Tarasov <lomereiter@gmail.com> 2012-07-10 10:23:29 PDT ---
The following code segfaults when I run it with "rdmd bug.d 0":

import std.stdio, std.conv;

float a, b = 0.0;
void main(string[] args) {
    try {
        a = to!float(args[1]);
    } finally {
        writeln(a / b);
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8369


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #1 from SomeDude <lovelydear@mailmetrash.com> 2012-12-31 13:59:45 PST ---
http://dpaste.dzfl.pl/f48bd90a

This one gave me some surprising results on DPaste. The results are inconsistent from run to run.

A few times, I got

Application output:
a/b = nan
Application error:
core.exception.RangeError@/home/c891/c322.d(6): Range violation

But most of the times, I get a "successful" run without any output.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8369


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru


--- Comment #2 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-01-01 10:47:17 PST ---
First of all, it does not segfault on 2.061.

(In reply to comment #1)
> http://dpaste.dzfl.pl/f48bd90a
> 
> This one gave me some surprising results on DPaste. The results are inconsistent from run to run.
> 
> A few times, I got
> 
> Application output:
> a/b = nan
> Application error:
> core.exception.RangeError@/home/c891/c322.d(6): Range violation
> 
> But most of the times, I get a "successful" run without any output.

Are you sure you receive no output?

It seems for me the code works as expected. If you provide no args, you will have array bounds exception (what actually happens). Additionally a is defaulted to nan, so the program will also print nan in this case.

If you provide some float as a program argument, you will receive inf, -inf or nan depending on the argument.

So, I don't see any problem here. I checked 2.061 on win64. If on other platform it does not work properly, please provide source and specify platform. Otherwise this issue can be closed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8369


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #3 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-01-02 04:27:41 PST ---
Works on linux too. Closed.

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