Bug 8369 – try/finally block and float division by zero
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2012-07-10T10:23:00Z
Last change time
2013-01-02T04:27:41Z
Assigned to
nobody
Creator
lomereiter
Comments
Comment #0 by lomereiter — 2012-07-10T10:23:29Z
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);
}
}
Comment #1 by lovelydear — 2012-12-31T13:59:45Z
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.
Comment #2 by maxim — 2013-01-01T10:47:17Z
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.