From 5e005355224ddbc12ce37318ce749bbd77308266 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Sat, 27 Jul 2024 01:49:57 -0700 Subject: [PATCH] Prevent divide by 0 in calc_mean --- src/RageUtil.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index cf525a8b71..bd93bd5243 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -1195,6 +1195,10 @@ float calc_mean(const float* pStart, const float* pEnd) /* The Kahan summation algorithm is used here to prevent * situations where the low order bits may be lost. * https://en.wikipedia.org/wiki/Kahan_summation_algorithm */ + + if (pStart == pEnd) + return 0.0f; + float sum = 0.0f; float c = 0.0f; for (const float* p = pStart; p != pEnd; ++p)