From 7ec4d88b1d4b4dafa532fde5861bea0eee8baa9b Mon Sep 17 00:00:00 2001 From: Alex Harker Date: Mon, 16 Sep 2019 21:56:00 +0200 Subject: [PATCH] Fix loop condition for inputs of size 1 or less --- FrameLib_Objects/Vector/FrameLib_Peaks.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FrameLib_Objects/Vector/FrameLib_Peaks.cpp b/FrameLib_Objects/Vector/FrameLib_Peaks.cpp index c32cf5c7..794c7d45 100644 --- a/FrameLib_Objects/Vector/FrameLib_Peaks.cpp +++ b/FrameLib_Objects/Vector/FrameLib_Peaks.cpp @@ -81,7 +81,8 @@ void FrameLib_Peaks::process() if (sizeIn > 3 && (input[1] > input[2]) && (input[1] > input[3]) && (input[1] > input[0])) nPeaks++; } - for (unsigned long i = 2; i < (sizeIn - 2); i++) + + for (unsigned long i = 2; i < (std::max(sizeIn, 2UL) - 2); i++) if ((input[i] > input[i - 2]) && (input[i] > input[i - 1]) && (input[i] > input[i + 1]) && (input[i] > input[i + 2])) nPeaks++; @@ -116,7 +117,7 @@ void FrameLib_Peaks::process() } } - for (unsigned long i = 2; i < (sizeIn - 2); i++) + for (unsigned long i = 2; i < (std::max(sizeIn, 2UL) - 2); i++) { if ((input[i] > input[i - 2]) && (input[i] > input[i - 1]) && (input[i] > input[i + 1]) && (input[i] > input[i + 2])) {