From d0e380da1eae5aedcef002253e917665ba2941a6 Mon Sep 17 00:00:00 2001
From: Melissa Elkadi <melissa@episci.com>
Date: Mon, 18 Jan 2021 11:39:03 -0800
Subject: [PATCH] Updated array index check with macro def in log.h

---
 common/utils/LOG/log.h               | 6 ++++++
 openair2/PHY_INTERFACE/phy_stub_UE.c | 9 ++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h
index b5c7e1b1ab..27d1fee56d 100644
--- a/common/utils/LOG/log.h
+++ b/common/utils/LOG/log.h
@@ -54,6 +54,12 @@
 #include "T.h"
 #include <common/utils/utils.h>
 /*----------------------------------------------------------------------------*/
+#include <assert.h>
+#ifdef NDEBUG
+#warning assert is disabled
+#endif
+#define NUM_ELEMENTS(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
+#define CHECK_INDEX(ARRAY, INDEX) assert((INDEX) < NUM_ELEMENTS(ARRAY))
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index b01f7bbab5..39242c36b9 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -1949,9 +1949,10 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req)
     }
 
     int pdu_size = sf_rnti_mcs[sf].pdu_size;
+    CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size);
+    CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size);
     for (int n = 0; n < pdu_size; n++)
     {
-      assert(n < sizeof(sf_rnti_mcs[sf].drop_flag));
       if (sf_rnti_mcs[sf].rnti[n] == rnti)
       {
         return sf_rnti_mcs[sf].drop_flag[n];
@@ -1973,9 +1974,11 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req)
     uint8_t mcs = 99;
     int n = 0;
     int pdu_size = sf_rnti_mcs[sf].pdu_size;
+    CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size);
+    CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size);
+    CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size);
     for (n = 0; n < pdu_size; n++)
     {
-      assert(n < sizeof(sf_rnti_mcs[sf].drop_flag) && n < sizeof(sf_rnti_mcs[sf].mcs) && n < sizeof(sf_rnti_mcs[sf].rnti));
       if (sf_rnti_mcs[sf].rnti[n] == rnti)
       {
         mcs = sf_rnti_mcs[sf].mcs[n];
@@ -2049,7 +2052,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req)
 
     double drop_cutoff = ((double) rand() / (RAND_MAX));
     assert(drop_cutoff < 1);
-    bler_val = 0.6;
+    bler_val = 0.4;
 
     if (bler_val >= drop_cutoff)
     {
-- 
2.26.2