From 8cdba4ff2d8cac80d6f1e05770fc8ef8de072b0c Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Fri, 29 May 2020 11:59:40 +0200
Subject: [PATCH] CI: fix a few cppcheck errors

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 executables/main-fs6.c                                 |  7 +++++--
 openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c            |  2 +-
 openair1/PHY/NR_TRANSPORT/nr_prach.c                   |  7 ++-----
 openair1/PHY/NR_TRANSPORT/pucch_rx.c                   | 10 +++++-----
 .../PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c    |  2 +-
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c             |  2 +-
 openair1/SIMULATION/NR_PHY/dlsim.c                     |  4 +++-
 openair1/SIMULATION/NR_PHY/prachsim.c                  |  8 +++++++-
 openair1/SIMULATION/NR_PHY/ulsim.c                     |  9 ++++++---
 9 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/executables/main-fs6.c b/executables/main-fs6.c
index 52b3864d359..ffa44bd9787 100644
--- a/executables/main-fs6.c
+++ b/executables/main-fs6.c
@@ -1194,6 +1194,8 @@ void phy_procedures_eNB_TX_tosplit(uint8_t *bufferZone, PHY_VARS_eNB *eNB, L1_rx
   for (int i=0; i<NUMBER_OF_UE_MAX; i++) {
     int harq_pid;
     LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[i];
+    if (ulsch == NULL)
+      continue;
 
     if (ulsch->ue_type > NOCE)
       harq_pid = 0;
@@ -1209,9 +1211,10 @@ void phy_procedures_eNB_TX_tosplit(uint8_t *bufferZone, PHY_VARS_eNB *eNB, L1_rx
 
     for (int k=0; k<8; k++) {
       ulsch_harq = ulsch->harq_processes[k];
+      if (ulsch_harq == NULL)
+        continue;
 
-      if (ulsch &&
-          (ulsch->rnti>0) &&
+      if ((ulsch->rnti>0) &&
           (ulsch_harq->status == ACTIVE) &&
           (ulsch_harq->frame == frame) &&
           (ulsch_harq->subframe == subframe) &&
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 90492b99999..92fe7772011 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -495,7 +495,7 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,
   }
 
   AssertFatal(sumKr>0,
-              "[eNB] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, O_RI %d, O_ACK %d, G %d, subframe %d\n",
+              "[eNB] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, O_RI %d, O_ACK %d, G %u, subframe %d\n",
               frame_parms->Nid_cell,ulsch->rnti,x2,
               harq_pid,
               ulsch_harq->round,
diff --git a/openair1/PHY/NR_TRANSPORT/nr_prach.c b/openair1/PHY/NR_TRANSPORT/nr_prach.c
index 7ab553fe6bc..5c4d048a77a 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_prach.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_prach.c
@@ -366,6 +366,7 @@ void rx_nr_prach(PHY_VARS_gNB *gNB,
 		 uint16_t *max_preamble_delay
 		 )
 {
+  AssertFatal(gNB!=NULL,"Can only be called from gNB\n");
 
   int i;
 
@@ -405,7 +406,6 @@ void rx_nr_prach(PHY_VARS_gNB *gNB,
   
   nr_frequency_range_e freq_range;
 
-  AssertFatal(gNB!=NULL,"Can only be called from gNB\n");
   fp    = &gNB->frame_parms;
   nb_rx = fp->nb_antennas_rx;
   
@@ -420,8 +420,6 @@ void rx_nr_prach(PHY_VARS_gNB *gNB,
   uint8_t prach_fmt = get_nr_prach_fmt(prach_ConfigIndex,frame_type,freq_range);
   uint16_t N_ZC = (prach_fmt <4)?839:139;
 
-  AssertFatal(gNB!=NULL,"gNB is null\n");
-
   prach_ifft        = gNB->prach_vars.prach_ifft;
   prachF            = gNB->prach_vars.prachF;
   if (LOG_DEBUGFLAG(PRACH)){
@@ -456,8 +454,7 @@ void rx_nr_prach(PHY_VARS_gNB *gNB,
 
   AssertFatal(NCS!=99,"NCS has not been set\n");
 
-  if (gNB) start_meas(&gNB->rx_prach);
-
+  start_meas(&gNB->rx_prach);
 
   prach_root_sequence_map = (prach_fmt<4) ? prach_root_sequence_map_0_3 : prach_root_sequence_map_abc;
 
diff --git a/openair1/PHY/NR_TRANSPORT/pucch_rx.c b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
index 38b8e0a95c6..6dfbffc46e2 100644
--- a/openair1/PHY/NR_TRANSPORT/pucch_rx.c
+++ b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
@@ -392,7 +392,7 @@ void nr_decode_pucch1(  int32_t **rxdataF,
                         uint8_t timeDomainOCC,
                         uint8_t nr_bit) {
 #ifdef DEBUG_NR_PUCCH_RX
-  printf("\t [nr_generate_pucch1] start function at slot(nr_tti_tx)=%d payload=%d m0=%d nrofSymbols=%d startingSymbolIndex=%d startingPRB=%d startingPRB_intraSlotHopping=%d timeDomainOCC=%d nr_bit=%d\n",
+  printf("\t [nr_generate_pucch1] start function at slot(nr_tti_tx)=%d payload=%lp m0=%d nrofSymbols=%d startingSymbolIndex=%d startingPRB=%d startingPRB_intraSlotHopping=%d timeDomainOCC=%d nr_bit=%d\n",
          nr_tti_tx,payload,m0,nrofSymbols,startingSymbolIndex,startingPRB,startingPRB_intraSlotHopping,timeDomainOCC,nr_bit);
 #endif
   /*
@@ -402,7 +402,7 @@ void nr_decode_pucch1(  int32_t **rxdataF,
   // complex-valued symbol d_re, d_im containing complex-valued symbol d(0):
   int16_t d_re=0, d_im=0,d1_re=0,d1_im=0;
 #ifdef DEBUG_NR_PUCCH_RX
-  printf("\t [nr_generate_pucch1] sequence modulation: payload=%x \tde_re=%d \tde_im=%d\n",payload,d_re,d_im);
+  printf("\t [nr_generate_pucch1] sequence modulation: payload=%lp \tde_re=%d \tde_im=%d\n",payload,d_re,d_im);
 #endif
   /*
    * Defining cyclic shift hopping TS 38.211 Subclause 6.3.2.2.2
@@ -496,7 +496,7 @@ void nr_decode_pucch1(  int32_t **rxdataF,
         z_re_rx[i+n] = ((int16_t *)&rxdataF[0][re_offset])[0];
         z_im_rx[i+n] = ((int16_t *)&rxdataF[0][re_offset])[1];
 #ifdef DEBUG_NR_PUCCH_RX
-        printf("\t [nr_generate_pucch1] mapping PUCCH to RE \t amp=%d \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \tz_pucch[%d]=txptr(%d)=(x_n(l=%d,n=%d)=(%d,%d))\n",
+        printf("\t [nr_generate_pucch1] mapping PUCCH to RE \t amp=%d \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \tz_pucch[%d]=txptr(%u)=(x_n(l=%d,n=%d)=(%d,%d))\n",
                amp,frame_parms->ofdm_symbol_size,frame_parms->N_RB_DL,frame_parms->first_carrier_offset,i+n,re_offset,
                l,n,((int16_t *)&rxdataF[0][re_offset])[0],((int16_t *)&rxdataF[0][re_offset])[1]);
 #endif
@@ -507,7 +507,7 @@ void nr_decode_pucch1(  int32_t **rxdataF,
         z_dmrs_im_rx[i+n] = ((int16_t *)&rxdataF[0][re_offset])[1];
 //	printf("%d\t%d\t%d\n",l,z_dmrs_re_rx[i+n],z_dmrs_im_rx[i+n]);
 #ifdef DEBUG_NR_PUCCH_RX
-        printf("\t [nr_generate_pucch1] mapping DM-RS to RE \t amp=%d \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \tz_dm-rs[%d]=txptr(%d)=(x_n(l=%d,n=%d)=(%d,%d))\n",
+        printf("\t [nr_generate_pucch1] mapping DM-RS to RE \t amp=%d \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \tz_dm-rs[%d]=txptr(%u)=(x_n(l=%d,n=%d)=(%d,%d))\n",
                amp,frame_parms->ofdm_symbol_size,frame_parms->N_RB_DL,frame_parms->first_carrier_offset,i+n,re_offset,
                l,n,((int16_t *)&rxdataF[0][re_offset])[0],((int16_t *)&rxdataF[0][re_offset])[1]);
 #endif
@@ -1062,7 +1062,7 @@ void nr_decode_pucch2(PHY_VARS_gNB *gNB,
 	  r_im_ext[aa][15]=rp[aa][47];
 		  
 #ifdef DEBUG_NR_PUCCH_RX
-	  for (int i=0;i<8;i++) printf("Ant %d PRB %d dmrs[%d] -> (%d,%d)\n",aa,prb+(i>>2),i,rd_re_ext[aa][i],rd_im_ext[aa],i);
+	  for (int i=0;i<8;i++) printf("Ant %d PRB %d dmrs[%d] -> (%d,%d)\n",aa,prb+(i>>2),i,rd_re_ext[aa][i],rd_im_ext[aa]);
 #endif
 	} // aa
      } // prb
diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
index 19564bd8d08..71a5771f5be 100644
--- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
+++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
@@ -618,7 +618,7 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 
 #ifdef DEBUG_PDCCH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+	printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
 
         multadd_real_vector_complex_scalar(fr,
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 498257154b2..69b3421ace1 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -167,13 +167,13 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                              0,
                                              harq_process_ul_ue->pusch_pdu.nrOfLayers);
 
-    TBS = harq_process_ul_ue->pusch_pdu.pusch_data.tb_size;
     uint8_t access_mode = SCHEDULED_ACCESS;
 
     //-----------------------------------------------------//
     // to be removed later when MAC is ready
 
     if (harq_process_ul_ue != NULL){
+      TBS = harq_process_ul_ue->pusch_pdu.pusch_data.tb_size;
       data_existing = 0;
 
     	if (IS_SOFTMODEM_NOS1){
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index 5c0573acbdc..0b51901b059 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -869,7 +869,7 @@ int main(int argc, char **argv)
       
       if (errors_scrambling > 0) {
 	if (n_trials == 1)
-	  printf("errors_scrambling = %d/%d (trial %d)\n", errors_scrambling, available_bits,trial);
+	  printf("errors_scrambling = %u/%u (trial %d)\n", errors_scrambling, available_bits,trial);
       }
       
       if (errors_bit > 0) {
@@ -977,6 +977,8 @@ int main(int argc, char **argv)
   if (input_fd)
     fclose(input_fd);
 
+  if (scg_fd)
+    fclose(scg_fd);
   return(n_errors);
   
 }
diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c
index e6106ce4625..2ad89ce897c 100644
--- a/openair1/SIMULATION/NR_PHY/prachsim.c
+++ b/openair1/SIMULATION/NR_PHY/prachsim.c
@@ -188,21 +188,27 @@ int main(int argc, char **argv)
 
       case 'H':
         channel_model=Rayleigh8;
+        break;
 
       case 'I':
         channel_model=Rayleigh1;
+        break;
 
       case 'J':
         channel_model=Rayleigh1_corr;
+        break;
 
       case 'K':
         channel_model=Rayleigh1_anticorr;
+        break;
 
       case 'L':
         channel_model=Rice8;
+        break;
 
       case 'M':
         channel_model=Rice1;
+        break;
 
       case 'N':
         channel_model=Rayleigh1_800;
@@ -628,7 +634,7 @@ int main(int argc, char **argv)
         }
       }
 
-      printf("SNR %f dB, UE Speed %f km/h: errors %d/%d (delay %f)\n",SNR,ue_speed,prach_errors,n_frames,delay_avg/(double)(n_frames-prach_errors));
+      printf("SNR %f dB, UE Speed %f km/h: errors %u/%d (delay %f)\n",SNR,ue_speed,prach_errors,n_frames,delay_avg/(double)(n_frames-prach_errors));
       //printf("(%f,%f)\n",ue_speed,(double)prach_errors/(double)n_frames);
     } // UE Speed loop
 
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 35e66127193..169b82bf8d7 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -724,7 +724,7 @@ int main(int argc, char **argv)
 
         if (errors_scrambling > 0) {
 	  if (n_trials==1)
-	    printf("\x1B[31m""[frame %d][trial %d]\tnumber of errors in unscrambling = %d\n" "\x1B[0m", frame, trial, errors_scrambling);
+	    printf("\x1B[31m""[frame %d][trial %d]\tnumber of errors in unscrambling = %u\n" "\x1B[0m", frame, trial, errors_scrambling);
         }
 
         for (i = 0; i < TBS; i++) {
@@ -742,13 +742,13 @@ int main(int argc, char **argv)
         if (errors_decoding > 0) {
           n_false_positive++;
 	  if (n_trials==1)
-	    printf("\x1B[31m""[frame %d][trial %d]\tnumber of errors in decoding     = %d\n" "\x1B[0m", frame, trial, errors_decoding);
+	    printf("\x1B[31m""[frame %d][trial %d]\tnumber of errors in decoding     = %u\n" "\x1B[0m", frame, trial, errors_decoding);
         } 
 
       } // trial loop
 
       printf("*****************************************\n");
-      printf("SNR %f: n_errors (negative CRC) = %d/%d, false_positive %d/%d, errors_scrambling %d/%d\n", SNR, n_errors, n_trials, n_false_positive, n_trials, errors_scrambling, n_trials);
+      printf("SNR %f: n_errors (negative CRC) = %d/%d, false_positive %d/%d, errors_scrambling %u/%d\n", SNR, n_errors, n_trials, n_false_positive, n_trials, errors_scrambling, n_trials);
       printf("\n");
       printf("SNR %f: Channel BLER %e, Channel BER %e\n", SNR,(double)n_errors/n_trials,(double)errors_scrambling/available_bits/n_trials);
       printf("*****************************************\n");
@@ -791,5 +791,8 @@ int main(int argc, char **argv)
   if (input_fd)
     fclose(input_fd);
 
+  if (scg_fd)
+    fclose(scg_fd);
+
   return (n_errors);
 }
-- 
GitLab