From 6cd917fca5505ad3ab8d4c3306db0ee5a30b03f1 Mon Sep 17 00:00:00 2001 From: Alejandro Leal Conejos Date: Wed, 27 Oct 2021 11:47:40 +0200 Subject: [PATCH] Fixes coverity 370816 --- srsenb/hdr/stack/mac/sched_ue_ctrl/sched_dl_cqi.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_dl_cqi.h b/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_dl_cqi.h index 39f24bec4..352d34c68 100644 --- a/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_dl_cqi.h +++ b/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_dl_cqi.h @@ -182,8 +182,16 @@ private: /// TS 36.321, Table 7.2.2-2 static uint32_t nof_bandwidth_parts(uint32_t nof_prb) { - static const uint32_t nrb[] = {0, 2, 2, 3, 4, 4}; - return nrb[srsran::lte_cell_nof_prb_to_index(nof_prb)]; + static const uint32_t nrb_size = 6u; + static const uint32_t nrb[] = {0, 2, 2, 3, 4, 4}; + uint32_t index = srsran::lte_cell_nof_prb_to_index(nof_prb); + + srsran_assert(index < nrb_size, "nrb index out of bounds"); + + // Fix error out of bounds, returns the array's first element by default. + index = (index < nrb_size) ? index : 0; + + return nrb[index]; } uint32_t J() const { return nof_bandwidth_parts(); }