[Issue 733] New: std.conv.toFloat does not catch errors
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 23 10:57:51 PST 2006
http://d.puremagic.com/issues/show_bug.cgi?id=733
Summary: std.conv.toFloat does not catch errors
Product: D
Version: 0.177
Platform: All
OS/Version: All
Status: NEW
Severity: minor
Priority: P2
Component: Phobos
AssignedTo: bugzilla at digitalmars.com
ReportedBy: dvdfrdmn at users.sf.net
In rare cases, toFloat will not throw an exception on invalid input. Also
affects toDouble and toReal.
-------
import std.conv;
import std.stdio;
void main() {
char[] b = "\x00";
bool ok = false;
try {
float f = toFloat(b);
} catch (ConvError e) {
ok = true;
}
assert(ok);
}
-------
General fix:
f = strtof(sz, &endptr);
if (getErrno() == ERANGE)
goto Lerr;
- if (endptr && (endptr == s.ptr || *endptr != 0))
+ if (endptr && (endptr == sz || *endptr != 0))
goto Lerr;
return f;
--
More information about the Digitalmars-d-bugs
mailing list