[pypy-svn] r59409 - in pypy/trunk/pypy/objspace/std: . test

fijal at codespeak.net fijal at codespeak.net
Sat Oct 25 20:35:09 CEST 2008


Author: fijal
Date: Sat Oct 25 20:35:07 2008
New Revision: 59409

Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/test/test_stringobject.py
   pypy/trunk/pypy/objspace/std/unicodeobject.py
Log:
Try to hack differently...


Modified: pypy/trunk/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/stringobject.py	Sat Oct 25 20:35:07 2008
@@ -506,7 +506,8 @@
     try:
         # XXX conservative estimate. If your strings are that close
         # to overflowing, bad luck.
-        ovfcheck(len(substrings_w) * len(by) + len(input))
+        one = ovfcheck(len(substrings_w) * len(by))
+        ovfcheck(one + len(input))
     except OverflowError:
         raise OperationError(
             space.w_OverflowError, 

Modified: pypy/trunk/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_stringobject.py	Sat Oct 25 20:35:07 2008
@@ -744,6 +744,9 @@
         iterable = "hello"
         raises(TypeError, len, iter(iterable))
 
+    def test_overflow_replace(self):
+        x = "A" * (2**16)
+        raises(OverflowError, x.replace, '', x)
 
 class AppTestPrebuilt(AppTestStringObject):
     def setup_class(cls):

Modified: pypy/trunk/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/unicodeobject.py	Sat Oct 25 20:35:07 2008
@@ -801,7 +801,8 @@
         parts = _split_into_chars(self, maxsplit)
 
     try:
-        ovfcheck(len(parts) * len(w_new._value) + len(w_self._value))
+        one = ovfcheck(len(parts) * len(w_new._value))
+        ovfcheck(one + len(w_self._value))
     except OverflowError:
         raise OperationError(
             space.w_OverflowError, 
@@ -867,7 +868,8 @@
         pad = tabsize - prevsize % tabsize
         nextpart = parts[i]
         try:
-            totalsize = ovfcheck(totalsize + pad + len(nextpart))
+            totalsize = ovfcheck(totalsize + pad)
+            totalsize = ovfcheck(totalsize + len(nextpart))
             result.append(u' ' * pad)
         except (OverflowError, MemoryError):
             raise OperationError(space.w_OverflowError, space.wrap('new string is too long'))



More information about the Pypy-commit mailing list