From 99ef760b6f5735359d2480cc0167e06a5cb3a97b Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 31 Jan 2018 16:48:50 +0100 Subject: [PATCH] More Coverity fixes --- lib/include/srslte/upper/rlc_am.h | 4 +- lib/src/phy/phch/sch.c | 9 ++++- lib/src/phy/phch/test/pdsch_test.c | 21 +++------- lib/src/phy/phch/test/prach_test_usrp.c | 4 +- lib/src/phy/phch/uci.c | 54 +++++++++++++++---------- lib/src/phy/sync/test/pss_file.c | 4 +- lib/src/phy/sync/test/pss_usrp.c | 4 +- lib/src/phy/ue/ue_dl.c | 2 +- lib/src/upper/pdcp.cc | 9 ++++- lib/src/upper/pdcp_entity.cc | 11 +++++ lib/src/upper/rlc.cc | 16 ++++++-- lib/src/upper/rlc_am.cc | 14 +++++-- lib/src/upper/rlc_tm.cc | 4 ++ lib/src/upper/rlc_um.cc | 8 ++++ lib/test/common/logger_test.cc | 15 +++++-- lib/test/common/timeout_test.cc | 1 + lib/test/upper/rlc_am_test.cc | 5 ++- lib/test/upper/rlc_um_test.cc | 5 ++- srsenb/hdr/mac/ue.h | 17 +++++++- srsenb/hdr/phy/phch_common.h | 12 +++++- srsenb/hdr/phy/phch_worker.h | 6 ++- srsenb/hdr/phy/prach_worker.h | 15 ++++++- srsenb/hdr/upper/rrc.h | 24 ++++++++++- srsenb/src/enb.cc | 9 +++-- srsenb/src/enb_cfg_parser.cc | 6 +-- 25 files changed, 204 insertions(+), 75 deletions(-) diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index c0289956c..e28e11618 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -180,8 +180,8 @@ private: int build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t retx); int build_data_pdu(uint8_t *payload, uint32_t nof_bytes); - void handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t header); - void handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t header); + void handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t &header); + void handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t &header); void handle_control_pdu(uint8_t *payload, uint32_t nof_bytes); void reassemble_rx_sdus(); diff --git a/lib/src/phy/phch/sch.c b/lib/src/phy/phch/sch.c index 3a8285f73..e6b7d49b9 100644 --- a/lib/src/phy/phch/sch.c +++ b/lib/src/phy/phch/sch.c @@ -89,7 +89,8 @@ uint32_t srslte_sch_find_Ioffset_cqi(float beta) { int srslte_sch_init(srslte_sch_t *q) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q) { + if (q) { + ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_sch_t)); if (srslte_crc_init(&q->crc_tb, SRSLTE_LTE_CRC24A, 24)) { @@ -753,7 +754,11 @@ int srslte_ulsch_uci_encode(srslte_sch_t *q, uint32_t nb_q = cfg->nbits.nof_bits; uint32_t Qm = cfg->grant.Qm; - + + if (Qm == 0) { + return SRSLTE_ERROR_INVALID_INPUTS; + } + if (uci_data.uci_ri_len > 0) { float beta = beta_ri_offset[cfg->uci_cfg.I_offset_ri]; if (cfg->cb_segm.tbs == 0) { diff --git a/lib/src/phy/phch/test/pdsch_test.c b/lib/src/phy/phch/test/pdsch_test.c index 3e4aa5abc..27802d7c3 100644 --- a/lib/src/phy/phch/test/pdsch_test.c +++ b/lib/src/phy/phch/test/pdsch_test.c @@ -178,21 +178,10 @@ int main(int argc, char **argv) { goto quit; } - switch(mimo_type) { - - case SRSLTE_MIMO_TYPE_SINGLE_ANTENNA: - cell.nof_ports = 1; - break; - case SRSLTE_MIMO_TYPE_SPATIAL_MULTIPLEX: - case SRSLTE_MIMO_TYPE_CDD: - if (nof_rx_antennas < 2) { - ERROR("At least two receiving antennas are required"); - goto quit; - } - case SRSLTE_MIMO_TYPE_TX_DIVERSITY: - default: - cell.nof_ports = 2; - break; + if (mimo_type == SRSLTE_MIMO_TYPE_SINGLE_ANTENNA) { + cell.nof_ports = 1; + } else { + cell.nof_ports = 2; } srslte_ra_dl_dci_t dci; @@ -250,7 +239,7 @@ int main(int argc, char **argv) { for (i=0;i 1e6) { - if (30720%((int) srate/1000) == 0) { + if (srate > 1e6 && (srate/1000) > 0) { + if (30720%(srate/1000) == 0) { srslte_rf_set_master_clock_rate(&rf, 30.72e6); } else { srslte_rf_set_master_clock_rate(&rf, 23.04e6); diff --git a/lib/src/phy/phch/uci.c b/lib/src/phy/phch/uci.c index 43de2937e..1b7b43ecb 100644 --- a/lib/src/phy/phch/uci.c +++ b/lib/src/phy/phch/uci.c @@ -655,11 +655,19 @@ int srslte_uci_encode_ack(srslte_pusch_cfg_t *cfg, uint8_t acks[2], uint32_t nof uint32_t nof_encoded_bits = encode_ri_ack(acks, nof_acks, q_encoded_bits, cfg->grant.Qm); - for (uint32_t i=0;igrant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ack_bits[cfg->grant.Qm*i]); - uci_ulsch_interleave_put(&q_encoded_bits[(i*cfg->grant.Qm)%nof_encoded_bits], cfg->grant.Qm, &ack_bits[cfg->grant.Qm*i]); + if (nof_encoded_bits > 0) { + for (uint32_t i = 0; i < Qprime; i++) { + uci_ulsch_interleave_ack_gen(i, + cfg->grant.Qm, + H_prime_total, + cfg->nbits.nof_symb, + cfg->cp, + &ack_bits[cfg->grant.Qm * i]); + uci_ulsch_interleave_put(&q_encoded_bits[(i * cfg->grant.Qm) % nof_encoded_bits], + cfg->grant.Qm, + &ack_bits[cfg->grant.Qm * i]); + } } - return (int) Qprime; } @@ -706,25 +714,27 @@ int srslte_uci_encode_ack_ri(srslte_pusch_cfg_t *cfg, uint32_t nof_encoded_bits = encode_ri_ack(data, data_len, q_encoded_bits, cfg->grant.Qm); - for (uint32_t i = 0; i < Qprime; i++) { - if (ack_ri) { - uci_ulsch_interleave_ri_gen(i, - cfg->grant.Qm, - H_prime_total, - cfg->nbits.nof_symb, - cfg->cp, - &bits[cfg->grant.Qm * i]); - } else { - uci_ulsch_interleave_ack_gen(i, - cfg->grant.Qm, - H_prime_total, - cfg->nbits.nof_symb, - cfg->cp, - &bits[cfg->grant.Qm * i]); + if (nof_encoded_bits > 0) { + for (uint32_t i = 0; i < Qprime; i++) { + if (ack_ri) { + uci_ulsch_interleave_ri_gen(i, + cfg->grant.Qm, + H_prime_total, + cfg->nbits.nof_symb, + cfg->cp, + &bits[cfg->grant.Qm * i]); + } else { + uci_ulsch_interleave_ack_gen(i, + cfg->grant.Qm, + H_prime_total, + cfg->nbits.nof_symb, + cfg->cp, + &bits[cfg->grant.Qm * i]); + } + uci_ulsch_interleave_put(&q_encoded_bits[(i * cfg->grant.Qm) % nof_encoded_bits], + cfg->grant.Qm, + &bits[cfg->grant.Qm * i]); } - uci_ulsch_interleave_put(&q_encoded_bits[(i * cfg->grant.Qm) % nof_encoded_bits], - cfg->grant.Qm, - &bits[cfg->grant.Qm * i]); } return (int) Qprime; diff --git a/lib/src/phy/sync/test/pss_file.c b/lib/src/phy/sync/test/pss_file.c index 4087366ec..d1ec2a130 100644 --- a/lib/src/phy/sync/test/pss_file.c +++ b/lib/src/phy/sync/test/pss_file.c @@ -59,7 +59,7 @@ void usage(char *prog) { printf("Usage: %s [nlestodv] -i cell_id -f input_file_name\n", prog); printf("\t-n nof_frames [Default %d]\n", nof_frames); printf("\t-l N_id_2 to sync [Default use cell_id]\n"); - printf("\t-e Extended CP [Default Normal]\n", fft_size); + printf("\t-e Extended CP [Default Normal]\n"); printf("\t-s symbol_sz [Default %d]\n", fft_size); printf("\t-t threshold [Default %.2f]\n", threshold); printf("\t-o file read offset [Default %d]\n", file_offset); @@ -266,7 +266,7 @@ int main(int argc, char **argv) { } } else { - INFO("No space for CFO computation. Frame starts at \n",peak_idx); + INFO("No space for CFO computation. Frame starts at \n"); } if(srslte_sss_subframe(m0,m1) == 0) diff --git a/lib/src/phy/sync/test/pss_usrp.c b/lib/src/phy/sync/test/pss_usrp.c index 70881f15b..d82555c95 100644 --- a/lib/src/phy/sync/test/pss_usrp.c +++ b/lib/src/phy/sync/test/pss_usrp.c @@ -61,7 +61,7 @@ void usage(char *prog) { printf("\t-g RF Gain [Default %.2f dB]\n", rf_gain); printf("\t-n nof_frames [Default %d]\n", nof_frames); printf("\t-l N_id_2 to sync [Default use cell_id]\n"); - printf("\t-e Extended CP [Default Normal]\n", fft_size); + printf("\t-e Extended CP [Default Normal]\n"); printf("\t-s symbol_sz [Default %d]\n", fft_size); printf("\t-t threshold [Default %.2f]\n", threshold); #ifndef DISABLE_GRAPHICS @@ -291,7 +291,7 @@ int main(int argc, char **argv) { } } else { - INFO("No space for CFO computation. Frame starts at \n",peak_idx); + INFO("No space for CFO computation. Frame starts at \n"); } if(srslte_sss_subframe(m0,m1) == 0) diff --git a/lib/src/phy/ue/ue_dl.c b/lib/src/phy/ue/ue_dl.c index 5c61b2c22..cbd84093a 100644 --- a/lib/src/phy/ue/ue_dl.c +++ b/lib/src/phy/ue/ue_dl.c @@ -896,7 +896,7 @@ static int find_dl_dci_type_crnti(srslte_ue_dl_t *q, uint32_t tm, uint32_t cfi, dci_blind_search_t *current_ss = &search_space; if (cfi < 1 || cfi > 3) { - ERROR("CFI must be 1 ≤ cfi ≤ 3", cfi); + ERROR("CFI must be 1 ≤ cfi ≤ 3 (cfi=%d)", cfi); return SRSLTE_ERROR; } diff --git a/lib/src/upper/pdcp.cc b/lib/src/upper/pdcp.cc index 320f02450..188c56c97 100644 --- a/lib/src/upper/pdcp.cc +++ b/lib/src/upper/pdcp.cc @@ -30,7 +30,14 @@ namespace srslte { pdcp::pdcp() -{} +{ + rlc = NULL; + rrc = NULL; + gw = NULL; + pdcp_log = NULL; + lcid = 0; + direction = 0; +} void pdcp::init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_, srsue::gw_interface_pdcp *gw_, log *pdcp_log_, uint32_t lcid_, uint8_t direction_) { diff --git a/lib/src/upper/pdcp_entity.cc b/lib/src/upper/pdcp_entity.cc index 84c90d931..c7970ddd6 100644 --- a/lib/src/upper/pdcp_entity.cc +++ b/lib/src/upper/pdcp_entity.cc @@ -35,6 +35,17 @@ pdcp_entity::pdcp_entity() ,tx_count(0) { pool = byte_buffer_pool::get_instance(); + log = NULL; + rlc = NULL; + rrc = NULL; + gw = NULL; + lcid = 0; + sn_len_bytes = 0; + do_integrity = false; + do_encryption = false; + rx_count = 0; + cipher_algo = CIPHERING_ALGORITHM_ID_EEA0; + integ_algo = INTEGRITY_ALGORITHM_ID_EIA0; } void pdcp_entity::init(srsue::rlc_interface_pdcp *rlc_, diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index 7a7180e45..e9c84e456 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -35,6 +35,15 @@ namespace srslte { rlc::rlc() { pool = byte_buffer_pool::get_instance(); + rlc_log = NULL; + pdcp = NULL; + rrc = NULL; + mac_timers = NULL; + ue = NULL; + default_lcid = 0; + bzero(metrics_time, sizeof(metrics_time)); + bzero(ul_tput_bytes, sizeof(ul_tput_bytes)); + bzero(dl_tput_bytes, sizeof(dl_tput_bytes)); } void rlc::init(srsue::pdcp_interface_rlc *pdcp_, @@ -233,7 +242,7 @@ void rlc::add_bearer(uint32_t lcid) void rlc::add_bearer(uint32_t lcid, srslte_rlc_config_t cnfg) { - if(lcid < 0 || lcid >= SRSLTE_N_RADIO_BEARERS) { + if(lcid >= SRSLTE_N_RADIO_BEARERS) { rlc_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); return; } @@ -271,10 +280,9 @@ void rlc::add_bearer(uint32_t lcid, srslte_rlc_config_t cnfg) *******************************************************************************/ bool rlc::valid_lcid(uint32_t lcid) { - if(lcid < 0 || lcid >= SRSLTE_N_RADIO_BEARERS) { + if(lcid >= SRSLTE_N_RADIO_BEARERS) { return false; - } - if(!rlc_array[lcid].active()) { + } else if(!rlc_array[lcid].active()) { return false; } return true; diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index f4e7839c4..f668b18d4 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -38,6 +38,12 @@ namespace srslte { rlc_am::rlc_am() : tx_sdu_queue(16) { + log = NULL; + pdcp = NULL; + rrc = NULL; + lcid = 0; + bzero(&cfg, sizeof(srslte_rlc_am_config_t)); + tx_sdu = NULL; rx_sdu = NULL; pool = byte_buffer_pool::get_instance(); @@ -768,7 +774,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) return (ptr-payload) + pdu->N_bytes; } -void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t header) +void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t &header) { std::map::iterator it; @@ -806,7 +812,7 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h memcpy(pdu.buf->msg, payload, nof_bytes); pdu.buf->N_bytes = nof_bytes; - pdu.header = header; + memcpy(&pdu.header, &header, sizeof(rlc_amd_pdu_header_t)); rx_window[header.sn] = pdu; @@ -865,7 +871,7 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h debug_state(); } -void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t header) +void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t &header) { std::map::iterator it; @@ -891,7 +897,7 @@ void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_a } memcpy(segment.buf->msg, payload, nof_bytes); segment.buf->N_bytes = nof_bytes; - segment.header = header; + memcpy(&segment.header, &header, sizeof(rlc_amd_pdu_header_t)); // Check if we already have a segment from the same PDU it = rx_segments.find(header.sn); diff --git a/lib/src/upper/rlc_tm.cc b/lib/src/upper/rlc_tm.cc index 843236ca8..bcf3cd20a 100644 --- a/lib/src/upper/rlc_tm.cc +++ b/lib/src/upper/rlc_tm.cc @@ -31,6 +31,10 @@ namespace srslte { rlc_tm::rlc_tm() : ul_queue(16) { + log = NULL; + pdcp = NULL; + rrc = NULL; + lcid = 0; pool = byte_buffer_pool::get_instance(); } diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 85fc9f818..6990a2798 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -33,6 +33,14 @@ namespace srslte { rlc_um::rlc_um() : tx_sdu_queue(16) { + log = NULL; + pdcp = NULL; + rrc = NULL; + reordering_timer = NULL; + lcid = 0; + reordering_timer_id = 0; + bzero(&cfg, sizeof(srslte_rlc_um_config_t)); + tx_sdu = NULL; rx_sdu = NULL; pool = byte_buffer_pool::get_instance(); diff --git a/lib/test/common/logger_test.cc b/lib/test/common/logger_test.cc index 845d4c104..1e0d86b50 100644 --- a/lib/test/common/logger_test.cc +++ b/lib/test/common/logger_test.cc @@ -67,7 +67,7 @@ void write(std::string filename) { bool read(std::string filename) { bool pass = true; bool written[NTHREADS][NMSGS]; - int thread, msg; + int thread = 0, msg = 0; int r; for(int i=0;ienb_files.rr_config, &phy_cnfg); - cell->phich_length = (srslte_phich_length_t) phichcfg.dur; - cell->phich_resources = (srslte_phich_resources_t) phichcfg.res; + cell->phich_length = (srslte_phich_length_t) (int) phichcfg.dur; + cell->phich_resources = (srslte_phich_resources_t) (int) phichcfg.res; if (!srslte_cell_isvalid(cell)) { fprintf(stderr, "Invalid cell parameters: nof_prb=%d, cell_id=%d\n", args->enb.n_prb, args->enb.s1ap.cell_id); @@ -845,7 +845,7 @@ int enb::parse_rr(all_args_t* args, rrc_cfg_t* rrc_cfg) { /* Transmission mode config section */ - if (args->enb.transmission_mode < 0 || args->enb.transmission_mode > 4) { + if (args->enb.transmission_mode < 1 || args->enb.transmission_mode > 4) { ERROR("Invalid transmission mode (%d). Only indexes 1-4 are implemented.\n", args->enb.transmission_mode); return SRSLTE_ERROR; } else if (args->enb.transmission_mode == 1 && args->enb.nof_ports > 1) {