From 7d58b3d5daaa56d75354b83dc9cbb2a72267467f Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Fri, 9 Apr 2021 21:42:43 +0200 Subject: [PATCH] Protect frame values against signed/unsigned casts --- src/sfizz/Defaults.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sfizz/Defaults.cpp b/src/sfizz/Defaults.cpp index b4d90053..e46039ee 100644 --- a/src/sfizz/Defaults.cpp +++ b/src/sfizz/Defaults.cpp @@ -4,6 +4,7 @@ namespace sfz { namespace Default { constexpr auto uint32_t_max = std::numeric_limits::max(); +constexpr auto int32_t_max = std::numeric_limits::max(); constexpr auto float_max = std::numeric_limits::max(); using FloatSpec = const OpcodeSpec; @@ -20,15 +21,15 @@ template using ESpec = const OpcodeSpec; FloatSpec delay { 0.0f, {0.0f, 100.0f}, kPermissiveBounds }; FloatSpec delayRandom { 0.0f, {0.0f, 100.0f}, kPermissiveBounds }; FloatSpec delayMod { 0.0f, {0.0f, 100.0f}, kPermissiveBounds }; -Int64Spec offset { 0, {0, uint32_t_max}, kPermissiveBounds }; -Int64Spec offsetMod { 0, {0, uint32_t_max}, kPermissiveBounds }; -Int64Spec offsetRandom { 0, {0, uint32_t_max}, kPermissiveBounds }; -Int64Spec sampleEnd { uint32_t_max, {0, uint32_t_max}, kEnforceBounds }; -Int64Spec sampleEndMod { 0, {-uint32_t_max, uint32_t_max}, kPermissiveBounds }; +Int64Spec offset { 0, {0, int32_t_max}, kPermissiveBounds }; +Int64Spec offsetMod { 0, {0, int32_t_max}, kPermissiveBounds }; +Int64Spec offsetRandom { 0, {0, int32_t_max}, kPermissiveBounds }; +Int64Spec sampleEnd { int32_t_max, {0, int32_t_max}, kEnforceBounds }; +Int64Spec sampleEndMod { 0, {-int32_t_max, int32_t_max}, kPermissiveBounds }; UInt32Spec sampleCount { 0, {0, uint32_t_max}, kEnforceUpperBound }; -Int64Spec loopStart { 0, {0, uint32_t_max}, kEnforceUpperBound }; -Int64Spec loopEnd { uint32_t_max, {0, uint32_t_max}, kEnforceUpperBound }; -Int64Spec loopMod { 0, {-uint32_t_max, uint32_t_max}, kPermissiveBounds }; +Int64Spec loopStart { 0, {0, int32_t_max}, kEnforceUpperBound }; +Int64Spec loopEnd { int32_t_max, {0, int32_t_max}, kEnforceUpperBound }; +Int64Spec loopMod { 0, {-int32_t_max, int32_t_max}, kPermissiveBounds }; UInt32Spec loopCount { 0, {0, uint32_t_max}, kEnforceUpperBound }; FloatSpec loopCrossfade { 1e-3, {1e-3, 1.0f}, kEnforceLowerBound|kPermissiveUpperBound }; ESpec oscillator { OscillatorEnabled::Auto, {OscillatorEnabled::Auto, OscillatorEnabled::On}, 0 };