diff options
author | Tom Tsou <tom.tsou@ettus.com> | 2016-07-28 11:14:08 -0700 |
---|---|---|
committer | Tom Tsou <tom.tsou@ettus.com> | 2016-07-28 11:48:25 -0700 |
commit | d6920df6303bf3004f34cc888a06948c399f09a5 (patch) | |
tree | bc03412b0427f5b352cff5a3456b16ed4f62f469 | |
parent | af3443385b4da3b951601a8d847cbf1101dfe51f (diff) |
trx: Fix coverity BER calculation NULL dereference
Allow output of encoded bit count or error count on BER calculation
without requiring both pointers to exist.
Change-Id: I2c78fa6a92a3b3da4aad8f70353e5a43451b0aa5
Fixes: Coverity CID 137963
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
-rw-r--r-- | src/osmo-bts-trx/gsm0503_coding.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/osmo-bts-trx/gsm0503_coding.c b/src/osmo-bts-trx/gsm0503_coding.c index c601cac3..4c4f7f1e 100644 --- a/src/osmo-bts-trx/gsm0503_coding.c +++ b/src/osmo-bts-trx/gsm0503_coding.c @@ -442,30 +442,33 @@ struct gsm0503_mcs_code gsm0503_mcs_dl_codes[EGPRS_NUM_MCS] = { }, }; -int osmo_conv_decode_ber(const struct osmo_conv_code *code, +static int osmo_conv_decode_ber(const struct osmo_conv_code *code, const sbit_t *input, ubit_t *output, int *n_errors, int *n_bits_total) { - int res, i; + int res, i, coded_len; ubit_t recoded[EGPRS_DATA_C_MAX]; res = osmo_conv_decode(code, input, output); - if (n_bits_total) { - *n_bits_total = osmo_conv_encode(code, output, recoded); - OSMO_ASSERT(sizeof(recoded)/sizeof(recoded[0]) >= *n_bits_total); + if (n_bits_total || n_errors) { + coded_len = osmo_conv_encode(code, output, recoded); + OSMO_ASSERT(sizeof(recoded)/sizeof(recoded[0]) >= coded_len); } /* Count bit errors */ if (n_errors) { *n_errors = 0; - for (i=0; i< *n_bits_total; i++) { + for (i = 0; i < coded_len; i++) { if (! ((recoded[i] && input[i]<0) || (!recoded[i] && input[i]>0)) ) *n_errors += 1; } } + if (n_bits_total) + *n_bits_total = coded_len; + return res; } |