Issue #27570: Avoid zero-length memcpy() calls with null source pointers
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 9f5c09d..0e6f515 100644
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -22,9 +22,9 @@
if test_support.have_unicode:
typecodes += "u"
-class BadConstructorTest(unittest.TestCase):
+class MiscTest(unittest.TestCase):
- def test_constructor(self):
+ def test_bad_constructor(self):
self.assertRaises(TypeError, array.array)
self.assertRaises(TypeError, array.array, spam=42)
self.assertRaises(TypeError, array.array, 'xx')
@@ -40,7 +40,17 @@
self.assertRaises(ValueError, array.array, u'x')
self.assertRaises(ValueError, array.array, u'\x80')
-tests.append(BadConstructorTest)
+ def test_empty(self):
+ # Exercise code for handling zero-length arrays
+ a = array.array('B')
+ a[:] = a
+ self.assertEqual(len(a), 0)
+ self.assertEqual(len(a + a), 0)
+ self.assertEqual(len(a * 3), 0)
+ a += a
+ self.assertEqual(len(a), 0)
+
+tests.append(MiscTest)
class BaseTest(unittest.TestCase):
# Required class attributes (provided by subclasses