From 02614f2f1ac9ee1150f165df34546490612153aa Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Mon, 20 Nov 2017 10:22:40 -0600 Subject: 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. --- common/frac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common') 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 -- cgit v1.2.3