From 3ba724e7156d6a007abb34cb5168a00385ee2702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 19 Feb 2024 00:25:54 +0100 Subject: [PATCH] AudioEffectPitchShift: Prevent negative size memset (GCC warning) --- servers/audio/effects/audio_effect_pitch_shift.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index 11c1d44472c..ddb17e050a2 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -87,8 +87,10 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff double magn, phase, tmp, window, real, imag; double freqPerBin, expct; long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2; + unsigned long fftFrameBufferSize; /* set up some handy variables */ + fftFrameBufferSize = (unsigned long)fftFrameSize*sizeof(float); fftFrameSize2 = fftFrameSize/2; stepSize = fftFrameSize/osamp; freqPerBin = sampleRate/(double)fftFrameSize; @@ -160,8 +162,8 @@ 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)); + memset(gSynMagn, 0, fftFrameBufferSize); + memset(gSynFreq, 0, fftFrameBufferSize); for (k = 0; k <= fftFrameSize2; k++) { index = k*pitchShift; if (index <= fftFrameSize2) { @@ -214,7 +216,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff } /* shift accumulator */ - memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); + memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameBufferSize); /* move input FIFO */ for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize];