From b0a6a569dff5aee5cadee57aea52e5ec9a03aa11 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 29 Oct 2018 22:38:32 +0100 Subject: [PATCH] pcm/FloatConvert: add `static_assert` on the factor This assertion currently fails for S32 due to integer overflow (#380). --- src/pcm/FloatConvert.hxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pcm/FloatConvert.hxx b/src/pcm/FloatConvert.hxx index 8022fd378..5a1756b36 100644 --- a/src/pcm/FloatConvert.hxx +++ b/src/pcm/FloatConvert.hxx @@ -35,6 +35,7 @@ struct FloatToIntegerSampleConvert { typedef typename DstTraits::value_type DV; static constexpr SV factor = 1 << (DstTraits::BITS - 1); + static_assert(factor > 0, "Wrong factor"); gcc_const static DV Convert(SV src) noexcept { @@ -54,6 +55,7 @@ struct IntegerToFloatSampleConvert { typedef typename DstTraits::value_type DV; static constexpr DV factor = 0.5 / (1 << (SrcTraits::BITS - 2)); + static_assert(factor > 0, "Wrong factor"); gcc_const static DV Convert(SV src) noexcept {