www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 733] New: std.conv.toFloat does not catch errors

reply d-bugmail puremagic.com writes:
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
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=733


bugzilla digitalmars.com changed:

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




------- Comment #1 from bugzilla digitalmars.com  2007-11-03 21:45 -------
Fixed dmd 1.023 (already worked in 2.006)


-- 
Nov 03 2007