From 2a5b2b1d4b8dbd0c13b45e91f244688850c5b159 Mon Sep 17 00:00:00 2001 From: DhanushPillay Date: Sun, 2 Aug 2026 18:17:36 +0530 Subject: [PATCH] Add safety iteration bound to boost fold() The fold() function in boost.h relies on an unbounded for (;;) loop. While it mathematically converges by halving the overshoot, floating-point precision limits can theoretically cause the convergence to stall just outside the threshold. If this happens, it hangs the audio core indefinitely. Added a hard limit of 20 iterations to guarantee bounded execution time for realtime safety. If it hits the limit, it returns the closest approximated value. --- Software/effects/boost.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Software/effects/boost.h b/Software/effects/boost.h index 56f208e..181bdc0 100644 --- a/Software/effects/boost.h +++ b/Software/effects/boost.h @@ -23,7 +23,8 @@ static float fold(float in, float level) { float fold_scale = 0.5; boost_effect.intense = 1; - for (;;) { + // Cap iterations to prevent infinite loop on float precision stalls + for (int i = 0; i < 20; i++) { float over = (in - level) * fold_scale; in = level - over; @@ -35,6 +36,7 @@ static float fold(float in, float level) if (in <= level) return in; } + return in; } static float boost_step(float in)