]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#3479: unichr(2**32) used to return u'\x00'.
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 31 Jul 2008 21:28:03 +0000 (21:28 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 31 Jul 2008 21:28:03 +0000 (21:28 +0000)
The argument was fetched in a long, but PyUnicode_FromOrdinal takes an int.

(why doesn't gcc issue a truncation warning in this case?)

Lib/test/test_builtin.py
Misc/NEWS
Python/bltinmodule.c

index 15d80a369831dc35a384844e57d94410a1e426d8..70980f8924f5e4eef5f02c3ac60134bdaa54c8a9 100644 (file)
@@ -1297,6 +1297,7 @@ class BuiltinTest(unittest.TestCase):
             )
             self.assertRaises(ValueError, unichr, sys.maxunicode+1)
             self.assertRaises(TypeError, unichr)
+            self.assertRaises((OverflowError, ValueError), unichr, 2**32)
 
     # We don't want self in vars(), so these are static methods
 
index 723d073f2ba8a5c89edee396580b9118a1b3ef43..8aa006a4713475e854ed46e3a6cc6ecd9bd8dab4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.6 beta 3?
 Core and Builtins
 -----------------
 
+- Issue #3479: On platforms where sizeof(int) is smaller than sizeof(long)
+  (64bit Unix, for example), unichr() would truncate its argument and return
+  u'\x00' for unichr(2**32). Now it properly raises an OverflowError.
+
 - Apply security patches from Apple.
 
 - Issue #2542: Now that issubclass() may call arbitrary code, ensure that
index e18eb2a95a90ac356af65d8ae295cbcf9bb77cbd..4a1ffd50f918ea05d08605f905067a099626136b 100644 (file)
@@ -394,9 +394,9 @@ Return a string of one character with ordinal i; 0 <= i < 256.");
 static PyObject *
 builtin_unichr(PyObject *self, PyObject *args)
 {
-       long x;
+       int x;
 
-       if (!PyArg_ParseTuple(args, "l:unichr", &x))
+       if (!PyArg_ParseTuple(args, "i:unichr", &x))
                return NULL;
 
        return PyUnicode_FromOrdinal(x);