[pypy-commit] pypy default: fix for when the hex string ends suddenly with 'P'

gutworth noreply at buildbot.pypy.org
Tue May 31 02:39:51 CEST 2011


Author: Benjamin Peterson <benjamin at python.org>
Branch: 
Changeset: r44605:a97d08283ea7
Date: 2011-05-30 19:52 -0500
http://bitbucket.org/pypy/pypy/changeset/a97d08283ea7/

Log:	fix for when the hex string ends suddenly with 'P'

diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py
--- a/pypy/objspace/std/floattype.py
+++ b/pypy/objspace/std/floattype.py
@@ -166,10 +166,10 @@
         if total_digits > min(const_one, const_two) // 4:
             raise OperationError(space.w_ValueError, space.wrap("way too long"))
         if i < length and (s[i] == "p" or s[i] == "P"):
+            i += 1
             if i == length:
                 raise OperationError(space.w_ValueError,
                                      space.wrap("invalid hex string"))
-            i += 1
             exp_sign = 1
             if s[i] == "-" or s[i] == "+":
                 if s[i] == "-":
diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -751,3 +751,6 @@
                 pass
             else:
                 self.identical(x, float.fromhex(x.hex()))
+
+    def test_invalid(self):
+        raises(ValueError, float.fromhex, "0P")


More information about the pypy-commit mailing list