From 280e28050aec75a61a908247565be029eef2c3b9 Mon Sep 17 00:00:00 2001 From: Erno Kilpelainen Date: Fri, 5 Jun 2026 10:53:56 +0000 Subject: [PATCH] Fix Medium Severity Coverity finding: CWE-369 (Division or modulo by float zero) (https://cwe.mitre.org/data/definitions/369.html) --- test/testcpp.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/testcpp.cc b/test/testcpp.cc index 50acada..5715a3f 100644 --- a/test/testcpp.cc +++ b/test/testcpp.cc @@ -25,6 +25,11 @@ using namespace std; template void dotest(int nfft) { + if (nfft <= 0) { + cerr << "invalid nfft:" << nfft << endl; + return; + } + typedef kissfft FFT; typedef std::complex cpx_type; @@ -59,7 +64,8 @@ void dotest(int nfft) complex dif = acc - x; difpower += norm(dif); } - cout << " RMSE:" << sqrt(difpower/totalpower) << "\t"; + const long double denom = (totalpower > 0) ? totalpower : 1e-30L; + cout << " RMSE:" << sqrt(difpower/denom) << "\t"; double t0 = curtime(); int nits=20e6/nfft;