← Back to index
|
Original Bugzilla link
Bug 733 – std.conv.toFloat does not catch errors
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2006-12-23T12:57:00Z
Last change time
2014-02-15T13:28:46Z
Assigned to
bugzilla
Creator
dvdfrdmn
Comments
Comment #0
by dvdfrdmn — 2006-12-23T12:57:50Z
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;
Comment #1
by bugzilla — 2007-11-03T21:45:40Z
Fixed dmd 1.023 (already worked in 2.006)