diff options
author | Colin Snover | 2017-11-20 10:22:40 -0600 |
---|---|---|
committer | Colin Snover | 2017-12-01 19:22:24 -0600 |
commit | 02614f2f1ac9ee1150f165df34546490612153aa (patch) | |
tree | 04e2af9057d5cc53538ab25036af27d00664338c | |
parent | 9a36870e78cd678842384d1beadc74115d9c232d (diff) | |
download | scummvm-rg350-02614f2f1ac9ee1150f165df34546490612153aa.tar.gz scummvm-rg350-02614f2f1ac9ee1150f165df34546490612153aa.tar.bz2 scummvm-rg350-02614f2f1ac9ee1150f165df34546490612153aa.zip |
COMMON: Fix UB shifting negative integers
Compilers optimise these back into shifts on architectures where
shifts of negative integers work the same as mul/div, so this
solves the UB without actually causing any performance issue.
-rw-r--r-- | common/frac.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/common/frac.h b/common/frac.h index d71d31645b..4e3bcf267f 100644 --- a/common/frac.h +++ b/common/frac.h @@ -46,7 +46,7 @@ typedef int32 frac_t; inline frac_t doubleToFrac(double value) { return (frac_t)(value * FRAC_ONE); } inline double fracToDouble(frac_t value) { return ((double)value) / FRAC_ONE; } -inline frac_t intToFrac(int16 value) { return value << FRAC_BITS; } -inline int16 fracToInt(frac_t value) { return value >> FRAC_BITS; } +inline frac_t intToFrac(int16 value) { return value * (1 << FRAC_BITS); } +inline int16 fracToInt(frac_t value) { return value / (1 << FRAC_BITS); } #endif |