mirror of https://github.com/python/cpython
make _tkinter._flatten check the result of PySequence_Size for errors #3880
This commit is contained in:
parent
4a69410e9f
commit
b3619be995
|
@ -2,10 +2,19 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
import _tkinter
|
||||||
from test import test_support
|
from test import test_support
|
||||||
from Tkinter import Tcl
|
from Tkinter import Tcl
|
||||||
from _tkinter import TclError
|
from _tkinter import TclError
|
||||||
|
|
||||||
|
|
||||||
|
class TkinterTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def testFlattenLen(self):
|
||||||
|
# flatten(<object with no length>)
|
||||||
|
self.assertRaises(TypeError, _tkinter._flatten, True)
|
||||||
|
|
||||||
|
|
||||||
class TclTest(unittest.TestCase):
|
class TclTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -151,7 +160,7 @@ class TclTest(unittest.TestCase):
|
||||||
os.environ['DISPLAY'] = old_display
|
os.environ['DISPLAY'] = old_display
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(TclTest)
|
test_support.run_unittest(TclTest, TkinterTest)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -2908,7 +2908,9 @@ Tkinter_Flatten(PyObject* self, PyObject* args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
context.maxsize = PySequence_Size(item);
|
context.maxsize = PySequence_Size(item);
|
||||||
if (context.maxsize <= 0)
|
if (context.maxsize < 0)
|
||||||
|
return NULL;
|
||||||
|
if (context.maxsize == 0)
|
||||||
return PyTuple_New(0);
|
return PyTuple_New(0);
|
||||||
|
|
||||||
context.tuple = PyTuple_New(context.maxsize);
|
context.tuple = PyTuple_New(context.maxsize);
|
||||||
|
|
Loading…
Reference in New Issue