summaryrefslogtreecommitdiff
path: root/Modules/audioop.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/audioop.c')
-rw-r--r--Modules/audioop.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 5c6925870d..3f047623eb 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -27,7 +27,8 @@ typedef short PyInt16;
#endif
static const int maxvals[] = {0, 0x7F, 0x7FFF, 0x7FFFFF, 0x7FFFFFFF};
-static const int minvals[] = {0, -0x80, -0x8000, -0x800000, -0x80000000};
+/* -1 trick is needed on Windows to support -0x80000000 without a warning */
+static const int minvals[] = {0, -0x80, -0x8000, -0x800000, -0x7FFFFFFF-1};
static const unsigned int masks[] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
static int
@@ -385,7 +386,9 @@ audioop_minmax(PyObject *self, PyObject *args)
signed char *cp;
Py_ssize_t len, i;
int size, val = 0;
- int min = 0x7fffffff, max = -0x80000000;
+ /* -1 trick below is needed on Windows to support -0x80000000 without
+ a warning */
+ int min = 0x7fffffff, max = -0x7FFFFFFF-1;
if (!PyArg_ParseTuple(args, "s#i:minmax", &cp, &len, &size))
return NULL;
@@ -530,7 +533,6 @@ audioop_findfit(PyObject *self, PyObject *args)
best_result = result;
best_j = 0;
- j = 0;
for ( j=1; j<=len1-len2; j++) {
aj_m1 = (double)cp1[j-1];
@@ -616,7 +618,6 @@ audioop_findmax(PyObject *self, PyObject *args)
best_result = result;
best_j = 0;
- j = 0;
for ( j=1; j<=len1-len2; j++) {
aj_m1 = (double)cp1[j-1];
@@ -1103,8 +1104,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
PyErr_SetString(AudioopError, "# of channels should be >= 1");
return NULL;
}
- bytes_per_frame = size * nchannels;
- if (bytes_per_frame / nchannels != size) {
+ if (size > INT_MAX / nchannels) {
/* This overflow test is rigorously correct because
both multiplicands are >= 1. Use the argument names
from the docs for the error msg. */
@@ -1112,6 +1112,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
"width * nchannels too big for a C int");
return NULL;
}
+ bytes_per_frame = size * nchannels;
if (weightA < 1 || weightB < 0) {
PyErr_SetString(AudioopError,
"weightA should be >= 1, weightB should be >= 0");
@@ -1431,7 +1432,6 @@ audioop_lin2adpcm(PyObject *self, PyObject *args)
if ( state == Py_None ) {
/* First time, it seems. Set defaults */
valpred = 0;
- step = 7;
index = 0;
} else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
return 0;
@@ -1532,7 +1532,6 @@ audioop_adpcm2lin(PyObject *self, PyObject *args)
if ( state == Py_None ) {
/* First time, it seems. Set defaults */
valpred = 0;
- step = 7;
index = 0;
} else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
return 0;