diff options
author | Tristan Matthews <tmatth@videolan.org> | 2019-02-28 18:58:58 +0300 |
---|---|---|
committer | Tristan Matthews <tmatth@videolan.org> | 2019-06-18 23:05:49 +0300 |
commit | a5ab348fc6e9dd54eb6ad11a3fd02faba624b470 (patch) | |
tree | bf672283c2f50ad08692682eac932af71a9a3f7a | |
parent | 6916e56dc5d31a7b9b2f61d19ff8f86c86d4dcfc (diff) |
fixed: make left shift macros use unsigned to avoid undefined behaviour
Backported from opus commit 1ee139bca076a1a3606a8a924a698d356d40cbb8
-rw-r--r-- | libspeex/fixed_debug.h | 4 | ||||
-rw-r--r-- | libspeex/fixed_generic.h | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/libspeex/fixed_debug.h b/libspeex/fixed_debug.h index 54f3866..10cb2fa 100644 --- a/libspeex/fixed_debug.h +++ b/libspeex/fixed_debug.h @@ -122,7 +122,7 @@ static inline short _SHL16(int a, int shift, char *file, int line) { fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line); } - res = a<<shift; + res = (int)((unsigned)a<<shift); if (!VERIFY_SHORT(res)) fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, file, line); spx_mips++; @@ -151,7 +151,7 @@ static inline int SHL32(long long a, int shift) { fprintf (stderr, "SHL32: inputs are not int: %d %d\n", (int)a, shift); } - res = a<<shift; + res = (long long)((unsigned long long)a<<shift); if (!VERIFY_INT(res)) { fprintf (stderr, "SHL32: output is not int: %d\n", (int)res); diff --git a/libspeex/fixed_generic.h b/libspeex/fixed_generic.h index 3fb096e..ddccf1b 100644 --- a/libspeex/fixed_generic.h +++ b/libspeex/fixed_generic.h @@ -43,9 +43,9 @@ #define EXTRACT16(x) ((spx_word16_t)(x)) #define EXTEND32(x) ((spx_word32_t)(x)) #define SHR16(a,shift) ((a) >> (shift)) -#define SHL16(a,shift) ((a) << (shift)) +#define SHL16(a,shift) ((spx_int16_t)((spx_uint16_t)(a) << (shift))) #define SHR32(a,shift) ((a) >> (shift)) -#define SHL32(a,shift) ((a) << (shift)) +#define SHL32(a,shift) ((spx_int32_t)((spx_uint32_t)(a) << (shift))) #define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift)) #define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift)) #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) @@ -53,7 +53,7 @@ #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) #define SHR(a,shift) ((a) >> (shift)) -#define SHL(a,shift) ((spx_word32_t)(a) << (shift)) +#define SHL(a,shift) ((spx_int32_t)((spx_uint32_t)(a) << (shift))) #define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) |