[Python-checkins] cpython (3.4): Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with

serhiy.storchaka python-checkins at python.org
Thu Sep 11 10:04:36 CEST 2014


http://hg.python.org/cpython/rev/6a96c28f9474
changeset:   92398:6a96c28f9474
branch:      3.4
parent:      92395:1223c882253f
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Sep 11 10:57:13 2014 +0300
summary:
  Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
empty string or tuple argument.

On some platforms Tcl memory allocator returns NULL when allocating zero-sized
block of memory.

files:
  Lib/test/test_tcl.py |  3 ++-
  Misc/NEWS            |  3 +++
  Modules/_tkinter.c   |  4 ++++
  3 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -416,7 +416,6 @@
         self.assertEqual(passValue((1, '2', (3.4,))),
                          (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
 
-    @unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX')
     def test_user_command(self):
         result = None
         def testfunc(arg):
@@ -444,9 +443,11 @@
         check('string')
         check('string\xbd')
         check('string\u20ac')
+        check('')
         check(b'string', 'string')
         check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
         check(b'string\xbd', 'string\xbd')
+        check(b'', '')
         check('str\x00ing')
         check('str\x00ing\xbd')
         check('str\x00ing\u20ac')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@
 Library
 -------
 
+- Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
+  empty string or tuple argument.
+
 - Issue #21951: Tkinter now most likely raises MemoryError instead of crash
   if the memory allocation fails.
 
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -899,6 +899,8 @@
         Py_ssize_t size, i;
 
         size = PyTuple_Size(value);
+        if (size == 0)
+            return Tcl_NewListObj(0, NULL);
         if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
             PyErr_SetString(PyExc_OverflowError, "tuple is too long");
             return NULL;
@@ -925,6 +927,8 @@
 
         inbuf = PyUnicode_DATA(value);
         size = PyUnicode_GET_LENGTH(value);
+        if (size == 0)
+            return Tcl_NewUnicodeObj((const void *)"", 0);
         if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) {
             PyErr_SetString(PyExc_OverflowError, "string is too long");
             return NULL;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list