From b6f8280f67ac813a0b130754688aa27528d37e77 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 27 Jul 2021 13:28:42 +0200 Subject: [PATCH] cqi: protect potential div by zero bug --- lib/src/phy/phch/cqi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/phy/phch/cqi.c b/lib/src/phy/phch/cqi.c index 0dd98a4b9..988a39128 100644 --- a/lib/src/phy/phch/cqi.c +++ b/lib/src/phy/phch/cqi.c @@ -589,7 +589,13 @@ uint32_t srsran_cqi_get_sb_idx(uint32_t tti, */ int srsran_cqi_hl_get_L(int nof_prb) { - return (int)ceil((float)nof_prb / cqi_hl_get_subband_size(nof_prb) / cqi_hl_get_bwp_J(nof_prb)); + int subband_size = cqi_hl_get_subband_size(nof_prb); + int bwp_J = cqi_hl_get_bwp_J(nof_prb); + if (subband_size <= 0 || bwp_J <= 0) { + ERROR("Invalid parameters"); + return SRSRAN_ERROR; + } + return (int)ceil(log2((float)nof_prb / subband_size / bwp_J)); } bool srsran_cqi_periodic_ri_send(const srsran_cqi_report_cfg_t* cfg, uint32_t tti, srsran_frame_type_t frame_type)