shithub: opus

Download patch

ref: 8489ff3ffa6930ee32a9616ca10c7dceceb05f8d
parent: 68d21fb5b0c1f38ef9fc82344094cf02103282c3
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Sat Jul 2 23:25:59 EDT 2022

Avoid undefined behaviour within the debug macros

Even when the macro itself would overflow.

Reviewed by Mark Harris

--- a/silk/MacroDebug.h
+++ b/silk/MacroDebug.h
@@ -55,7 +55,7 @@
 static OPUS_INLINE opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file, int line){
     opus_int32 ret;
 
-    ret = a + b;
+    ret = (opus_int32)((opus_uint32)a + (opus_uint32)b);
     if ( ret != silk_ADD_SAT32( a, b ) )
     {
         fprintf (stderr, "silk_ADD32(%d, %d) in %s: line %d\n", a, b, file, line);
@@ -257,7 +257,7 @@
 static OPUS_INLINE opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *file, int line){
     opus_int32 ret;
     opus_int64 ret64;
-    ret = a32 * b32;
+    ret = (opus_int32)((opus_uint32)a32 * (opus_uint32)b32);
     ret64 = (opus_int64)a32 * (opus_int64)b32;
     if ( (opus_int64)ret != ret64 )
     {