digitalmars.D.bugs - [Issue 733] New: std.conv.toFloat does not catch errors
- d-bugmail puremagic.com (37/37) Dec 23 2006 http://d.puremagic.com/issues/show_bug.cgi?id=733
- d-bugmail puremagic.com (9/9) Nov 03 2007 http://d.puremagic.com/issues/show_bug.cgi?id=733
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 digitalmars.com ReportedBy: dvdfrdmn 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; --
Dec 23 2006
http://d.puremagic.com/issues/show_bug.cgi?id=733 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed dmd 1.023 (already worked in 2.006) --
Nov 03 2007