Browse Source

modemdab: Fix integer division in symbol power calculation

Fix Coverity CID 657864 by using floating-point division when
normalizing symbol power. The previous integer division
discarded the fractional part of the divisor. Add 6 before
dividing by 7 to account for the loop stepping by 7 samples
and rounding the sample count up to include the final partial
step.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
chirpmodem-v8.1.0
Robin Getz 4 weeks ago
parent
commit
bf733989d1
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 2
      modemdab/dabofdm.cpp

2
modemdab/dabofdm.cpp

@ -736,7 +736,7 @@ bool DABFrontEnd::processFrame() @@ -736,7 +736,7 @@ bool DABFrontEnd::processFrame()
for (int n = ModeI::NullSize; n < ModeI::FrameSize; n += 7) {
symbolPower += std::norm(m_mixed[Margin + shift + n]);
}
symbolPower /= (ModeI::FrameSize - ModeI::NullSize) / 7;
symbolPower /= ((ModeI::FrameSize - ModeI::NullSize + 6) / 7.0);
m_frame.startSample = frameStart + shift;
m_frame.frequencyOffsetHz = static_cast<float>(m_frequency);

Loading…
Cancel
Save