From 9711d6a7cbbd67e3ab7b0fab8e28b84f15f7c6fb Mon Sep 17 00:00:00 2001 From: Erno Kilpelainen Date: Fri, 5 Jun 2026 11:06:24 +0000 Subject: [PATCH] Fix Medium Severity Coverity finding: CWE-252 (Ignoring number of bytes read) (https://cwe.mitre.org/data/definitions/252.html) --- tools/fftutil.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/fftutil.c b/tools/fftutil.c index 0a432c4..ef9be29 100644 --- a/tools/fftutil.c +++ b/tools/fftutil.c @@ -54,9 +54,16 @@ void fft_filend(FILE * fin,FILE * fout,int *dims,int ndims,int isinverse) buf = (kiss_fft_cpx *) malloc (sizeof (kiss_fft_cpx) * dimprod); st = kiss_fftnd_alloc (dims, ndims, isinverse, 0, 0); - while (fread (buf, sizeof (kiss_fft_cpx) * dimprod, 1, fin) > 0) { - kiss_fftnd (st, buf, buf); - fwrite (buf, sizeof (kiss_fft_cpx), dimprod, fout); + while (1) { + size_t nread = fread(buf, sizeof(kiss_fft_cpx), dimprod, fin); + if (nread == (size_t)dimprod) { + kiss_fftnd(st, buf, buf); + fwrite(buf, sizeof(kiss_fft_cpx), dimprod, fout); + continue; + } + if (nread != 0) + fprintf(stderr,"short read on nd complex input\n"); + break; } free (st); free (buf);