]> granicus.if.org Git - python/commitdiff
Issue #20394: Attempt to silence CID 1164423: Division or modulo by zero in audioop_r...
authorChristian Heimes <christian@python.org>
Mon, 27 Jan 2014 00:12:00 +0000 (01:12 +0100)
committerChristian Heimes <christian@python.org>
Mon, 27 Jan 2014 00:12:00 +0000 (01:12 +0100)
Serhiy and I had the same idea so it's most likely right. ;)

Modules/audioop.c

index cc3a020bde143e0a8d21b2f2f29c31f6969b09b8..159b2fbdc81a499bfe49395a01d3b8764593c69b 100644 (file)
@@ -1304,6 +1304,7 @@ audioop_ratecv_impl(PyModuleDef *module, Py_buffer *fragment, int width, int nch
             "weightA should be >= 1, weightB should be >= 0");
         return NULL;
     }
+    assert(fragment->len >= 0);
     if (fragment->len % bytes_per_frame != 0) {
         PyErr_SetString(AudioopError, "not a whole number of frames");
         return NULL;
@@ -1370,7 +1371,7 @@ audioop_ratecv_impl(PyModuleDef *module, Py_buffer *fragment, int width, int nch
            case ceiling(len/inrate) * outrate. */
 
         /* compute ceiling(len/inrate) without overflow */
-        Py_ssize_t q = len > 0 ? 1 + (len - 1) / inrate : 0;
+        Py_ssize_t q = 1 + (len - 1) / inrate;
         if (outrate > PY_SSIZE_T_MAX / q / bytes_per_frame)
             str = NULL;
         else