]> granicus.if.org Git - python/commitdiff
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
authorGeorg Brandl <georg@python.org>
Sat, 10 Jun 2006 06:40:50 +0000 (06:40 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 10 Jun 2006 06:40:50 +0000 (06:40 +0000)
Also improve error message on overflow.

Lib/test/string_tests.py
Objects/stringobject.c
Objects/unicodeobject.c

index 5a1cc8aa03e545d0cebff22a00811093eab6f678..236c529738e6c96886b7fe1e60fb98f474e8e090 100644 (file)
@@ -938,6 +938,8 @@ class MixinStrUnicodeUserStringTest:
         # test.test_string.StringTest.test_join)
         self.checkequal('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
         self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd'))
+        self.checkequal('bd', '', 'join', ('', 'b', '', 'd'))
+        self.checkequal('ac', '', 'join', ('a', '', 'c', ''))
         self.checkequal('w x y z', ' ', 'join', Sequence())
         self.checkequal('abc', 'a', 'join', ('abc',))
         self.checkequal('z', 'a', 'join', UserList(['z']))
index 831d54a06609f02aa26969015dfbb25fbad86039..a5c8cc287012ecd1ee53d65f8516c2f9588389b8 100644 (file)
@@ -1788,7 +1788,7 @@ string_join(PyStringObject *self, PyObject *orig)
                        sz += seplen;
                if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
                        PyErr_SetString(PyExc_OverflowError,
-                               "join() is too long for a Python string");
+                               "join() result is too long for a Python string");
                        Py_DECREF(seq);
                        return NULL;
                }
index bf2425c3cf546300d44675b1c907dc25be31b281..064caebd50c8a1a0508cab19a9b3bd4ae9a90113 100644 (file)
@@ -4491,11 +4491,11 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
         /* Make sure we have enough space for the separator and the item. */
        itemlen = PyUnicode_GET_SIZE(item);
        new_res_used = res_used + itemlen;
-       if (new_res_used <= 0)
+       if (new_res_used < 0)
            goto Overflow;
        if (i < seqlen - 1) {
            new_res_used += seplen;
-           if (new_res_used <= 0)
+           if (new_res_used < 0)
                goto Overflow;
        }
        if (new_res_used > res_alloc) {
@@ -4536,7 +4536,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
 
  Overflow:
     PyErr_SetString(PyExc_OverflowError,
-                    "join() is too long for a Python string");
+                    "join() result is too long for a Python string");
     Py_DECREF(item);
     /* fall through */