]> granicus.if.org Git - python/commitdiff
audioop: adpcm2lin() and lin2adpcm() now raises a TypeError instead of a
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 3 Jan 2014 02:26:47 +0000 (03:26 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 3 Jan 2014 02:26:47 +0000 (03:26 +0100)
SystemError if the state type is invalid.

Lib/test/test_audioop.py
Modules/audioop.c

index d5075450e63758b86f3038e3fd1c9e528a05b6e5..879adea2b8eb295a9992d5ed8873688207879453 100644 (file)
@@ -269,6 +269,11 @@ class TestAudioop(unittest.TestCase):
             self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None),
                              (b'\0' * 5, (0, 0)))
 
+    def test_invalid_adpcm_state(self):
+        # state must be a tuple or None, not an integer
+        self.assertRaises(TypeError, audioop.adpcm2lin, b'\0', 1, 555)
+        self.assertRaises(TypeError, audioop.lin2adpcm, b'\0', 1, 555)
+
     def test_lin2alaw(self):
         self.assertEqual(audioop.lin2alaw(datas[1], 1),
                          b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
index ae3ff060b4742ca3cd298ed7c1bcd935c1ac477c..bae4f2687e678c9e3d9fce76bdf53f508e9d6cac 100644 (file)
@@ -1525,6 +1525,9 @@ audioop_lin2adpcm(PyObject *self, PyObject *args)
         /* First time, it seems. Set defaults */
         valpred = 0;
         index = 0;
+    } else if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+        goto exit;
     } else if (!PyArg_ParseTuple(state, "ii", &valpred, &index))
         goto exit;
 
@@ -1631,6 +1634,9 @@ audioop_adpcm2lin(PyObject *self, PyObject *args)
         /* First time, it seems. Set defaults */
         valpred = 0;
         index = 0;
+    } else if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+        goto exit;
     } else if (!PyArg_ParseTuple(state, "ii", &valpred, &index))
         goto exit;