[pypy-svn] pypy default: strtod should fail when the string contains a \0

amauryfa commits-noreply at bitbucket.org
Thu Jan 27 01:53:36 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r41376:844553aad5e2
Date: 2011-01-27 01:25 +0100
http://bitbucket.org/pypy/pypy/changeset/844553aad5e2/

Log:	strtod should fail when the string contains a \0

diff --git a/pypy/rlib/test/test_rdtoa.py b/pypy/rlib/test/test_rdtoa.py
--- a/pypy/rlib/test/test_rdtoa.py
+++ b/pypy/rlib/test/test_rdtoa.py
@@ -10,6 +10,7 @@
     raises(ValueError, strtod, "")
     raises(ValueError, strtod, " ")
     raises(ValueError, strtod, "\0")
+    raises(ValueError, strtod, "3\09")
 
 def test_dtoa():
     assert dtoa(3.47) == "3.47"

diff --git a/pypy/rlib/rdtoa.py b/pypy/rlib/rdtoa.py
--- a/pypy/rlib/rdtoa.py
+++ b/pypy/rlib/rdtoa.py
@@ -45,10 +45,13 @@
         ll_input = rffi.str2charp(input)
         try:
             result = dg_strtod(ll_input, end_ptr)
-            if end_ptr[0] and (end_ptr[0] == ll_input or ord(end_ptr[0][0])):
-                offset = (rffi.cast(rffi.LONG, end_ptr[0]) -
-                          rffi.cast(rffi.LONG, ll_input))
-                raise ValueError("invalid input at position %d" % (offset,))
+
+            endpos = (rffi.cast(rffi.LONG, end_ptr[0]) -
+                      rffi.cast(rffi.LONG, ll_input))
+
+            if endpos == 0 or endpos < len(input):
+                raise ValueError("invalid input at position %d" % (endpos,))
+
             return result
         finally:
             rffi.free_charp(ll_input)


More information about the Pypy-commit mailing list