summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2022-07-03 03:25:59 -0400
committerJean-Marc Valin <jmvalin@amazon.com>2022-07-05 17:27:32 -0400
commit8489ff3ffa6930ee32a9616ca10c7dceceb05f8d (patch)
treed9194350aa2ae143f193e924029be659f85f11e3
parent68d21fb5b0c1f38ef9fc82344094cf02103282c3 (diff)
downloadopus-8489ff3ffa6930ee32a9616ca10c7dceceb05f8d.tar.gz
Avoid undefined behaviour within the debug macros
Even when the macro itself would overflow. Reviewed by Mark Harris
-rw-r--r--silk/MacroDebug.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/silk/MacroDebug.h b/silk/MacroDebug.h
index bf42d5f0..e505d02a 100644
--- a/silk/MacroDebug.h
+++ b/silk/MacroDebug.h
@@ -55,7 +55,7 @@ static OPUS_INLINE opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file
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_int64 silk_SUB_SAT64_( opus_int64 a64, opus_int64 b64, c
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 )
{