Fix Medium Severity Coverity finding:

CWE-369 (Division or modulo by float zero)
(https://cwe.mitre.org/data/definitions/369.html)
This commit is contained in:
Erno Kilpelainen
2026-06-05 10:53:56 +00:00
parent c11160e95f
commit 280e28050a
+7 -1
View File
@@ -25,6 +25,11 @@ using namespace std;
template <class T>
void dotest(int nfft)
{
if (nfft <= 0) {
cerr << "invalid nfft:" << nfft << endl;
return;
}
typedef kissfft<T> FFT;
typedef std::complex<T> cpx_type;
@@ -59,7 +64,8 @@ void dotest(int nfft)
complex<long double> 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;