]> granicus.if.org Git - python/commitdiff
Issue 3306. Better control for a lenght in findmax() function.
authorFacundo Batista <facundobatista@gmail.com>
Mon, 7 Jul 2008 17:02:59 +0000 (17:02 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Mon, 7 Jul 2008 17:02:59 +0000 (17:02 +0000)
Lib/test/test_audioop.py
Modules/audioop.c

index b94be91cda3e40f06d6447e5d1885cf97b20f24e..8d4f30b453e43e07b8735c7aaf6d86bca2697b24 100644 (file)
@@ -161,6 +161,10 @@ class TestAudioop(unittest.TestCase):
             self.assertEqual(audioop.getsample(data[1], 2, i), i)
             self.assertEqual(audioop.getsample(data[2], 4, i), i)
 
+    def test_negavitelen(self):
+        # from issue 3306, previously it segfaulted
+        self.assertRaises(audioop.error,
+            audioop.findmax, ''.join( chr(x) for x in xrange(256)), -2392392)
 
 def test_main():
     run_unittest(TestAudioop)
index 31e3fa4870e1210b961090f617ddb7ef60ed02ca..767cae64e9b56b2023e3a24a7cb5d0a1148cb6e7 100644 (file)
@@ -575,7 +575,7 @@ audioop_findmax(PyObject *self, PyObject *args)
         }
         len1 >>= 1;
     
-        if ( len1 < len2 ) {
+        if ( len2 < 0 || len1 < len2 ) {
                 PyErr_SetString(AudioopError, "Input sample should be longer");
                 return 0;
         }