From cc5fab28af0a37aa48a6f445e1ac5cc5ef80f933 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 29 Oct 2018 22:47:53 +0100 Subject: [PATCH] pcm/FloatConvert: fix compile-time integer overflow for S32 The compile-time calculation for `factor` overflows because `1<<31` cannot be represented by `int`. By casting to `uintmax_t` first, we can avoid this overflow. Closes #380 --- NEWS | 1 + src/pcm/FloatConvert.hxx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ffb1a2ef2..083855fd6 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ver 0.20.23 (not yet released) * protocol - emit "player" idle event when restarting the current song +* fix broken float to s32 conversion * new clang crash bug workaround ver 0.20.22 (2018/10/23) diff --git a/src/pcm/FloatConvert.hxx b/src/pcm/FloatConvert.hxx index 2270fbb90..70b00bcba 100644 --- a/src/pcm/FloatConvert.hxx +++ b/src/pcm/FloatConvert.hxx @@ -34,7 +34,7 @@ struct FloatToIntegerSampleConvert { typedef typename SrcTraits::long_type SL; typedef typename DstTraits::value_type DV; - static constexpr SV factor = 1 << (DstTraits::BITS - 1); + static constexpr SV factor = uintmax_t(1) << (DstTraits::BITS - 1); static_assert(factor > 0, "Wrong factor"); gcc_const