Description
In src/emon_CM.c at line 789, the calculation of numSamplesSqr can overflow:
const int32_t numSamples = accumProcessing->numSamples;
const int64_t numSamplesSqr = numSamples * numSamples;
The multiplication numSamples * numSamples is performed as int32_t * int32_t, yielding an int32_t result before being assigned to the int64_t variable. If numSamples exceeds ~46340, the multiplication overflows.
Expected behavior
The multiplication should be performed in 64-bit to prevent overflow:
const int64_t numSamplesSqr = (int64_t)numSamples * numSamples;
Or using unsigned types:
const uint32_t numSamples = accumProcessing->numSamples;
const uint64_t numSamplesSqr = (uint64_t)numSamples * numSamples;
Fix
This issue will be fixed along with PR #40.