diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index 03b2c10028e..d0251aa339c 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -418,7 +418,6 @@ def passValue(value): self.assertEqual(passValue(['a', ['b', 'c']]), ('a', ('b', 'c')) if self.wantobjects else 'a {b c}') - @unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX') def test_user_command(self): result = None def testfunc(arg): @@ -446,9 +445,11 @@ def float_eq(actual, expected): 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 index 079a0eb6a57..b9a112de894 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -132,6 +132,9 @@ Core and Builtins 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 index a8e6d9828ce..02fcb818a3f 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -906,6 +906,8 @@ AsObj(PyObject *value) Py_ssize_t size, i; size = PySequence_Fast_GET_SIZE(value); + if (size == 0) + return Tcl_NewListObj(0, NULL); if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) { PyErr_SetString(PyExc_OverflowError, PyTuple_Check(value) ? "tuple is too long" : @@ -936,6 +938,8 @@ AsObj(PyObject *value) 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;