aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael McTernan <mike.mcternan@wavemobile.com>2020-01-06 11:56:18 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2020-01-06 12:07:23 +0100
commitb54f1bf122e9e34613cfd8a90fd40abdc457e154 (patch)
tree139d3cc2a1ec1239e7188953a08a881f3b0b3691
parentee8f4b0a91dff21c2d7d8361afb6b41637fcdc29 (diff)
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
-rw-r--r--src/common/measurement.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/common/measurement.c b/src/common/measurement.c
index 12fd7794..3e0daf19 100644
--- a/src/common/measurement.c
+++ b/src/common/measurement.c
@@ -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;