From 36fc2513673a714eaa268a7ab531c5584e2c4507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 25 Apr 2025 12:27:28 +0200 Subject: [PATCH] AudioEffectPitchShift: 3rd attempt at fixing -Wstringop-overflow warning (cherry picked from commit 80359d3577e56e69e3395a256aacbd0484f00ded) --- servers/audio/effects/audio_effect_pitch_shift.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index beca5039046..e1f80df776c 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -160,8 +160,13 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff /* ***************** PROCESSING ******************* */ /* this does the actual pitch shifting */ - memset(gSynMagn, 0, fftFrameSize*sizeof(float)); - memset(gSynFreq, 0, fftFrameSize*sizeof(float)); + size_t fftBufferSize = static_cast(fftFrameSize) * sizeof(float); + if (unlikely(fftBufferSize > MAX_FRAME_LENGTH)) { + ERR_PRINT_ONCE("Invalid FFT frame size for PitchShift. This is a bug, please report."); + return; + } + memset(gSynMagn, 0, fftBufferSize); + memset(gSynFreq, 0, fftBufferSize); for (k = 0; k <= fftFrameSize2; k++) { index = k*pitchShift; if (index <= fftFrameSize2) { @@ -214,7 +219,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff } /* shift accumulator */ - memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); + memmove(gOutputAccum, gOutputAccum+stepSize, fftBufferSize); /* move input FIFO */ for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize];