Math: FFT: Fix possible right shift by negative

Cppcheck found this issue:

src/include/sof/math/fft.h:133:51: error: Shifting by a negative
value is undefined behaviour [shiftNegative]
  output->real = sat_int16((((int32_t)input->real >> n_rnd) + 1) >> 1);
                                                  ^
The case n == 0 need to be handled with the upper if branch non-rounded
shift version.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2022-08-29 16:21:43 +03:00 committed by Liam Girdwood
parent b4c09d769e
commit 40166c699b
1 changed files with 1 additions and 1 deletions

View File

@ -125,7 +125,7 @@ static inline void icomplex16_shift(struct icomplex16 *input, int16_t n, struct
{
int n_rnd = -n - 1;
if (n > 0) {
if (n >= 0) {
/* need saturation handling */
output->real = sat_int16((int32_t)input->real << n);
output->imag = sat_int16((int32_t)input->imag << n);