measurement: use signed integer for division of ta256b_sum

The variable ta256b_sum is int32_t and num_ul_meas_actual is unsigned
int. When ta256b_sum is negative the division produces the wrong result.

This is beacuse the division is performed unsigned as the usual
arithmetic conversions promote to unsigned where both both operands are
the same width.

Lets fix this by casting num_ul_meas_actual to signed.

(Note that in the same function there are various other averages
computed in the same pattern, but they have unsigned operands and so are
correct.)

Related: SYS#4728
Change-Id: I37e3f69109c5ca2948bd4cdb7aa017bf2fcb8172
This commit is contained in:
Michael McTernan 2020-01-06 11:56:18 +01:00 committed by Philipp Maier
parent ee8f4b0a91
commit b54f1bf122
1 changed files with 1 additions and 1 deletions

View File

@ -662,7 +662,7 @@ int lchan_meas_check_compute(struct gsm_lchan *lchan, uint32_t fn)
if (!num_ul_meas_actual)
ta256b_sum = lchan->meas.ms_toa256;
else
ta256b_sum = ta256b_sum / num_ul_meas_actual;
ta256b_sum = ta256b_sum / (signed)num_ul_meas_actual;
if (!num_meas_sub)
ber_sub_sum = MEASUREMENT_DUMMY_BER;