summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-07-19 03:05:42 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-07-19 03:05:42 (GMT)
commit6fb90905e2c5e42e19484046757fd098df2c6fcf (patch)
treef33b17ac72f2e4d1f337ef636859cfe20c1377ed /Modules
parente3d747496edf492c10e329512e1bab573843daf1 (diff)
downloadcpython-6fb90905e2c5e42e19484046757fd098df2c6fcf.zip
cpython-6fb90905e2c5e42e19484046757fd098df2c6fcf.tar.gz
cpython-6fb90905e2c5e42e19484046757fd098df2c6fcf.tar.bz2
Issue #1621: Avoid signed int negation overflow in audioop
Diffstat (limited to 'Modules')
-rw-r--r--Modules/audioop.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 8ca64c6..ed1eca3 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -446,7 +446,9 @@ audioop_max_impl(PyObject *module, Py_buffer *fragment, int width)
return NULL;
for (i = 0; i < fragment->len; i += width) {
int val = GETRAWSAMPLE(width, fragment->buf, i);
- if (val < 0) absval = (-val);
+ /* Cast to unsigned before negating. Unsigned overflow is well-
+ defined, but signed overflow is not. */
+ if (val < 0) absval = -(unsigned int)val;
else absval = val;
if (absval > max) max = absval;
}