From b429dbdc4b41d57ff00456c73646bb1f6f14d8b5 Mon Sep 17 00:00:00 2001 From: listeria <56203103+ListeriaM@users.noreply.github.com> Date: Fri, 24 May 2024 13:24:40 -0300 Subject: [PATCH] fix WaveCrop(): update wave->frameCount (#4003) also allow `finalFrame = wave->frameCount' as the range of frames does not include it. Co-authored-by: Listeria monocytogenes --- src/raudio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index e74f8590e..c6bd00165 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1278,7 +1278,7 @@ Wave WaveCopy(Wave wave) // NOTE: Security check in case of out-of-range void WaveCrop(Wave *wave, int initFrame, int finalFrame) { - if ((initFrame >= 0) && (initFrame < finalFrame) && ((unsigned int)finalFrame < wave->frameCount)) + if ((initFrame >= 0) && (initFrame < finalFrame) && ((unsigned int)finalFrame <= wave->frameCount)) { int frameCount = finalFrame - initFrame; @@ -1288,6 +1288,7 @@ void WaveCrop(Wave *wave, int initFrame, int finalFrame) RL_FREE(wave->data); wave->data = data; + wave->frameCount = (unsigned int)frameCount; } else TRACELOG(LOG_WARNING, "WAVE: Crop range out of bounds"); }