From 562590e5958c57ba795355f17a6a49bd4dcc16ae Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 14 Apr 2020 20:50:00 +0200 Subject: [PATCH] Fix LGTM warnings --- lib/include/srslte/phy/phch/pucch.h | 1 - lib/include/srslte/phy/phch/pucch_cfg.h | 4 ++-- lib/include/srslte/phy/utils/vector.h | 8 ++++--- lib/src/asn1/liblte_m2ap.cc | 31 +++++++++++-------------- lib/src/common/crash_handler.c | 6 ++--- lib/src/common/log_filter.cc | 18 +++++++------- lib/src/phy/ch_estimation/chest_dl.c | 7 ++++-- lib/src/phy/dft/dft_fftw.c | 18 +++++++------- lib/src/phy/fec/parity.h | 4 ++++ lib/src/phy/fec/viterbi37.h | 7 +++++- lib/src/phy/mimo/layermap.c | 2 +- lib/src/phy/mimo/precoding.c | 14 +++++------ lib/src/phy/modem/hard_demod_lte.c | 7 +++++- lib/src/phy/modem/lte_tables.h | 4 ++++ lib/src/phy/phch/npbch.c | 2 +- lib/src/phy/phch/pbch.c | 2 +- lib/src/phy/phch/prb_dl.h | 4 ++++ lib/src/phy/phch/sch.c | 2 +- lib/src/phy/phch/tbs_tables.h | 5 ++++ lib/src/phy/rf/rf_helper.h | 6 ++++- lib/src/phy/rf/rf_soapy_imp.h | 5 ++++ lib/src/phy/rf/rf_uhd_imp.h | 4 ++++ lib/src/phy/rf/rf_zmq_imp.c | 6 ++--- lib/src/phy/rf/rf_zmq_imp.h | 5 ++++ lib/src/phy/rf/rf_zmq_imp_tx.c | 2 +- lib/src/phy/rf/uhd_c_api.h | 4 ++++ lib/src/phy/utils/vector.c | 20 ++++++++++++---- lib/src/upper/rlc_am_lte.cc | 2 +- srsue/src/stack/rrc/rrc.cc | 8 ++++--- srsue/src/stack/upper/pcsc_usim.cc | 2 +- 30 files changed, 135 insertions(+), 75 deletions(-) diff --git a/lib/include/srslte/phy/phch/pucch.h b/lib/include/srslte/phy/phch/pucch.h index 0e5d08ab5..89521a341 100644 --- a/lib/include/srslte/phy/phch/pucch.h +++ b/lib/include/srslte/phy/phch/pucch.h @@ -45,7 +45,6 @@ #define SRSLTE_PUCCH_1A_2A_NOF_ACK (1) #define SRSLTE_PUCCH_1B_2B_NOF_ACK (2) #define SRSLTE_PUCCH3_NOF_BITS (4 * SRSLTE_NRE) -#define SRSLTE_PUCCH_MAX_BITS SRSLTE_CQI_MAX_BITS #define SRSLTE_PUCCH_MAX_SYMBOLS (SRSLTE_PUCCH_N_SEQ * SRSLTE_PUCCH2_N_SF * SRSLTE_NOF_SLOTS_PER_SF) // PUCCH Format 1B Channel selection diff --git a/lib/include/srslte/phy/phch/pucch_cfg.h b/lib/include/srslte/phy/phch/pucch_cfg.h index e174ffefb..1ae706ac2 100644 --- a/lib/include/srslte/phy/phch/pucch_cfg.h +++ b/lib/include/srslte/phy/phch/pucch_cfg.h @@ -29,7 +29,7 @@ #define SRSLTE_PUCCH_SIZE_AN_CS 4 #define SRSLTE_PUCCH_SIZE_AN_N3 4 #define SRSLTE_PUCCH_NOF_AN_CS 2 -#define SRSLTE_PUCCH2_MAX_DMRS_BITS 16 +#define SRSLTE_PUCCH_MAX_BITS SRSLTE_CQI_MAX_BITS typedef enum SRSLTE_API { SRSLTE_PUCCH_FORMAT_1 = 0, @@ -80,7 +80,7 @@ typedef struct SRSLTE_API { // PUCCH configuration generated during a call to encode/decode srslte_pucch_format_t format; uint16_t n_pucch; - uint8_t pucch2_drs_bits[SRSLTE_PUCCH2_MAX_DMRS_BITS]; + uint8_t pucch2_drs_bits[SRSLTE_PUCCH_MAX_BITS]; } srslte_pucch_cfg_t; diff --git a/lib/include/srslte/phy/utils/vector.h b/lib/include/srslte/phy/utils/vector.h index dbb0c977f..b55fef4ce 100644 --- a/lib/include/srslte/phy/utils/vector.h +++ b/lib/include/srslte/phy/utils/vector.h @@ -96,6 +96,11 @@ SRSLTE_API void srslte_vec_cf_zero(cf_t* ptr, uint32_t nsamples); SRSLTE_API void srslte_vec_f_zero(float* ptr, uint32_t nsamples); SRSLTE_API void srslte_vec_u8_zero(uint8_t* ptr, uint32_t nsamples); +/* Copy memory */ +SRSLTE_API void srs_vec_cf_copy(cf_t* dst, const cf_t* src, uint32_t len); +SRSLTE_API void srs_vec_f_copy(float* dst, const float* src, uint32_t len); +SRSLTE_API void srs_vec_u8_copy(uint8_t* dst, const uint8_t* src, uint32_t len); + /* print vectors */ SRSLTE_API void srslte_vec_fprint_c(FILE* stream, const cf_t* x, const uint32_t len); SRSLTE_API void srslte_vec_fprint_f(FILE* stream, const float* x, const uint32_t len); @@ -267,9 +272,6 @@ SRSLTE_API void srslte_vec_abs_dB_cf(const cf_t* x, float default_value, float* */ SRSLTE_API void srslte_vec_arg_deg_cf(const cf_t* x, float default_value, float* arg, const uint32_t len); -/* Copy 256 bit aligned vector */ -SRSLTE_API void srs_vec_cf_cpy(const cf_t* src, cf_t* dst, const int len); - SRSLTE_API void srslte_vec_interleave(const cf_t* x, const cf_t* y, cf_t* z, const int len); SRSLTE_API void srslte_vec_interleave_add(const cf_t* x, const cf_t* y, cf_t* z, const int len); diff --git a/lib/src/asn1/liblte_m2ap.cc b/lib/src/asn1/liblte_m2ap.cc index 22afa71fc..c77b0f67a 100644 --- a/lib/src/asn1/liblte_m2ap.cc +++ b/lib/src/asn1/liblte_m2ap.cc @@ -298,8 +298,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_protocolextensioncontainer(LIBLTE_M2AP_PROTOC // Length liblte_value_2_bits(ie->len - 1, ptr, 16); liblte_align_up_zero(ptr, 8); - uint32_t i; - for (i = 0; i < ie->len; i++) { + for (uint32_t i = 0; i < ie->len; i++) { if (liblte_m2ap_pack_protocolextensionfield(&ie->buffer[i], ptr) != LIBLTE_SUCCESS) { return LIBLTE_ERROR_ENCODE_FAIL; } @@ -324,8 +323,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_protocolextensioncontainer(uint8_t** ie->len); return LIBLTE_ERROR_DECODE_FAIL; } - uint32_t i; - for (i = 0; i < ie->len; i++) { + for (uint32_t i = 0; i < ie->len; i++) { if (liblte_m2ap_unpack_protocolextensionfield(ptr, &ie->buffer[i]) != LIBLTE_SUCCESS) { return LIBLTE_ERROR_DECODE_FAIL; } @@ -413,8 +411,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_ipaddress(LIBLTE_M2AP_IP_ADDRESS_STRUCT* ie, liblte_value_2_bits(ie->len - 4, ptr, 4); liblte_align_up_zero(ptr, 8); // Octets - uint32_t i; - for (i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { liblte_value_2_bits(ie->buffer[i], ptr, 8); } err = LIBLTE_SUCCESS; @@ -433,7 +430,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_ipaddress(uint8_t** ptr, LIBLTE_M2AP_IP_ADD if (ie->len > 16) { return LIBLTE_ERROR_DECODE_FAIL; } - for (int i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { ie->buffer[i] = liblte_bits_2_value(ptr, 8); } err = LIBLTE_SUCCESS; @@ -981,7 +978,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_mbmsserviceareaidlist(LIBLTE_M2AP_MBMS_SERVIC { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; liblte_value_2_bits(ie->len - 1, ptr, 8); - for (int i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { liblte_m2ap_pack_mbmsservicearea(&ie->buffer[i], ptr); } err = LIBLTE_SUCCESS; @@ -994,7 +991,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mbmsserviceareaidlist(uint8_t** LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; if (ie != NULL && ptr != NULL) { ie->len = liblte_bits_2_value(ptr, 8) + 1; - for (int i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { liblte_m2ap_unpack_mbmsservicearea(ptr, &ie->buffer[i]); } err = LIBLTE_SUCCESS; @@ -2106,7 +2103,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_enbmbmsconfigurationdatalist(LIBLTE_M2AP_ENB_ // Length liblte_value_2_bits(ie->len - 1, ptr, 8); - for (uint16_t i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { LIBLTE_BIT_MSG_STRUCT tmp_msg; uint8_t* tmp_ptr; @@ -2152,7 +2149,7 @@ liblte_m2ap_unpack_enbmbmsconfigurationdatalist(uint8_t** ptr, LIBLTE_M2AP_ENB_M return LIBLTE_ERROR_DECODE_FAIL; } - for (uint16_t i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { if (liblte_m2ap_unpack_protocolie_singlecontainer(ptr, &proto_container) != LIBLTE_SUCCESS) { return LIBLTE_ERROR_DECODE_FAIL; } @@ -2258,7 +2255,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_mbmssessionlistperpmchitem(LIBLTE_M2AP_MBMS_S // Length liblte_value_2_bits(ie->len - 1, ptr, 5); - for (int i = 0; i < ie->len; i++) { + for (uint16_t i = 0; i < ie->len; i++) { liblte_value_2_bits(ie->buffer[i].ext, ptr, 1); liblte_value_2_bits(ie->buffer[i].iE_Extensions_present, ptr, 1); @@ -2285,7 +2282,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mbmssessionlistperpmchitem(uint8_t** // Length ie->len = liblte_bits_2_value(ptr, 5) + 1; - for (int i = 0; i < ie->len; i++) { + for (uint16_t i = 0; i < ie->len; i++) { ie->buffer[i].ext = liblte_bits_2_value(ptr, 1); ie->buffer[i].iE_Extensions_present = liblte_bits_2_value(ptr, 1); // TMGI @@ -2410,7 +2407,7 @@ liblte_m2ap_pack_mbsfnsubframeconfigurationlist(LIBLTE_M2AP_MBSFN_SUBFRAME_CONFI liblte_value_2_bits(ie->len - 1, ptr, 3); liblte_align_up_zero(ptr, 8); - for (uint16_t i = 0; i < ie->len; i++) { + for (uint32_t i = 0; i < ie->len; i++) { LIBLTE_BIT_MSG_STRUCT tmp_msg; uint8_t* tmp_ptr; @@ -2458,7 +2455,7 @@ liblte_m2ap_unpack_mbsfnsubframeconfigurationlist(uint8_t** return LIBLTE_ERROR_DECODE_FAIL; } - for (uint16_t i = 0; i < ie->len; i++) { + for (uint32_t i = 0; i < ie->len; i++) { if (liblte_m2ap_unpack_protocolie_header(ptr, &ie_id, &crit, &len) != LIBLTE_SUCCESS) { return LIBLTE_ERROR_DECODE_FAIL; } @@ -2864,7 +2861,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_mbsfnareaconfigurationlist(LIBLTE_M2AP_MBSFN_ // Length liblte_value_2_bits(ie->len - 1, ptr, 8); - for (uint16_t i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { // ProtocolIE - MBSFN-Area-Configuration-Item err = liblte_m2ap_pack_mbsfnareaconfigurationitem(&ie->buffer[i], ptr); if (err != LIBLTE_SUCCESS) { @@ -2897,7 +2894,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mbsfnareaconfigurationlist(uint8_t** return LIBLTE_ERROR_DECODE_FAIL; } - for (uint16_t i = 0; i < ie->len; i++) { + for (uint8_t i = 0; i < ie->len; i++) { err = liblte_m2ap_unpack_mbsfnareaconfigurationitem(ptr, &ie->buffer[i]); if (err != LIBLTE_SUCCESS) return err; diff --git a/lib/src/common/crash_handler.c b/lib/src/common/crash_handler.c index ac05e7430..271bca6aa 100644 --- a/lib/src/common/crash_handler.c +++ b/lib/src/common/crash_handler.c @@ -39,13 +39,13 @@ static void crash_handler(int sig) printf("srsLTE crashed... we could not save backtrace in '%s'...\n", crash_file_name); } else { time_t lnTime; - struct tm* stTime; + struct tm stTime; char strdate[32]; time(&lnTime); - stTime = localtime(&lnTime); + gmtime_r(&lnTime, &stTime); - strftime(strdate, 32, "%d/%m/%Y %H:%M:%S", stTime); + strftime(strdate, sizeof(strdate), "%d/%m/%Y %H:%M:%S", &stTime); fprintf(f, "--- command='"); for (int i = 0; i < bt_argc; i++) { diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index e83b2f24a..20c5d29f4 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -234,9 +234,9 @@ void log_filter::get_tti_str(const uint32_t tti_, char* buffer, const uint32_t b void log_filter::now_time(char* buffer, const uint32_t buffer_len) { - struct timeval rawtime; - struct tm* timeinfo; - char us[16]; + timeval rawtime = {}; + tm timeinfo = {}; + char us[16]; srslte_timestamp_t now; uint64_t usec_epoch; @@ -247,16 +247,16 @@ void log_filter::now_time(char* buffer, const uint32_t buffer_len) } if (!time_src) { - gettimeofday(&rawtime, NULL); - timeinfo = localtime(&rawtime.tv_sec); + gettimeofday(&rawtime, nullptr); + gmtime_r(&rawtime.tv_sec, &timeinfo); if (time_format == TIME) { - strftime(buffer, buffer_len, "%H:%M:%S.", timeinfo); + strftime(buffer, buffer_len, "%H:%M:%S.", &timeinfo); snprintf(us, 16, "%06ld", rawtime.tv_usec); - uint32_t dest_len = strlen(buffer); + uint32_t dest_len = (uint32_t)strlen(buffer); strncat(buffer, us, buffer_len - dest_len - 1); } else { - usec_epoch = rawtime.tv_sec * 1000000 + rawtime.tv_usec; + usec_epoch = rawtime.tv_sec * 1000000UL + rawtime.tv_usec; snprintf(buffer, buffer_len, "%" PRIu64, usec_epoch); } } else { @@ -265,7 +265,7 @@ void log_filter::now_time(char* buffer, const uint32_t buffer_len) if (time_format == TIME) { snprintf(buffer, buffer_len, "%ld:%06u", now.full_secs, (uint32_t)(now.frac_secs * 1e6)); } else { - usec_epoch = now.full_secs * 1000000 + (uint32_t)(now.frac_secs * 1e6); + usec_epoch = now.full_secs * 1000000UL + (uint64_t)(now.frac_secs * 1e6); snprintf(buffer, buffer_len, "%" PRIu64, usec_epoch); } } diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index 015dcc5a0..75dc9d90c 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -156,8 +156,11 @@ clean_exit: void srslte_chest_dl_free(srslte_chest_dl_t* q) { - if (&q->csr_refs) - srslte_refsignal_free(&q->csr_refs); + if (!q) { + return; + } + + srslte_refsignal_free(&q->csr_refs); if (q->mbsfn_refs) { for (int i = 0; i < SRSLTE_MAX_MBSFN_AREA_IDS; i++) { diff --git a/lib/src/phy/dft/dft_fftw.c b/lib/src/phy/dft/dft_fftw.c index 4464a9337..9c6f85d68 100644 --- a/lib/src/phy/dft/dft_fftw.c +++ b/lib/src/phy/dft/dft_fftw.c @@ -106,8 +106,8 @@ int srslte_dft_replan(srslte_dft_plan_t* plan, const int new_dft_points) static void allocate(srslte_dft_plan_t* plan, int size_in, int size_out, int len) { - plan->in = fftwf_malloc(size_in * len); - plan->out = fftwf_malloc(size_out * len); + plan->in = fftwf_malloc((size_t)size_in * len); + plan->out = fftwf_malloc((size_t)size_out * len); } int srslte_dft_replan_guru_c(srslte_dft_plan_t* plan, @@ -294,11 +294,11 @@ static void copy_pre(uint8_t* dst, uint8_t* src, int size_d, int len, bool forwa int offset = dc ? 1 : 0; if (mirror && !forward) { int hlen = dft_floor(len, 2); - memset(dst, 0, size_d * offset); - memcpy(&dst[size_d * offset], &src[size_d * hlen], size_d * (len - hlen - offset)); - memcpy(&dst[(len - hlen) * size_d], src, size_d * hlen); + memset(dst, 0, (size_t)size_d * offset); + memcpy(&dst[size_d * offset], &src[size_d * hlen], (size_t)size_d * (len - hlen - offset)); + memcpy(&dst[(len - hlen) * size_d], src, (size_t)size_d * hlen); } else { - memcpy(dst, src, size_d * len); + memcpy(dst, src, (size_t)size_d * len); } } @@ -307,10 +307,10 @@ static void copy_post(uint8_t* dst, uint8_t* src, int size_d, int len, bool forw int offset = dc ? 1 : 0; if (mirror && forward) { int hlen = dft_ceil(len, 2); - memcpy(dst, &src[size_d * hlen], size_d * (len - hlen)); - memcpy(&dst[(len - hlen) * size_d], &src[size_d * offset], size_d * (hlen - offset)); + memcpy(dst, &src[size_d * hlen], (size_t)size_d * (len - hlen)); + memcpy(&dst[(len - hlen) * size_d], &src[size_d * offset], (size_t)size_d * (hlen - offset)); } else { - memcpy(dst, src, size_d * len); + memcpy(dst, src, (size_t)size_d * len); } } diff --git a/lib/src/phy/fec/parity.h b/lib/src/phy/fec/parity.h index c0a21d178..8cceed4e8 100644 --- a/lib/src/phy/fec/parity.h +++ b/lib/src/phy/fec/parity.h @@ -18,6 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ +#ifndef SRSLTE_PARITY_H_ +#define SRSLTE_PARITY_H_ #include @@ -53,3 +55,5 @@ static inline uint32_t parity(int x) x ^= (x >> 8); return parityb(x); } + +#endif /* SRSLTE_PARITY_H_ */ diff --git a/lib/src/phy/fec/viterbi37.h b/lib/src/phy/fec/viterbi37.h index 85b302900..048440640 100644 --- a/lib/src/phy/fec/viterbi37.h +++ b/lib/src/phy/fec/viterbi37.h @@ -19,6 +19,9 @@ * */ +#ifndef SRSLTE_VITERBI37_H_ +#define SRSLTE_VITERBI37_H_ + #include void* create_viterbi37_port(int polys[3], uint32_t len); @@ -77,4 +80,6 @@ int chainback_viterbi37_avx2_16bit(void* p, uint8_t* data, uint32_t nbits, uint3 void delete_viterbi37_avx2_16bit(void* p); -int update_viterbi37_blk_avx2_16bit(void* p, uint16_t* syms, uint32_t nbits, uint32_t* best_state); \ No newline at end of file +int update_viterbi37_blk_avx2_16bit(void* p, uint16_t* syms, uint32_t nbits, uint32_t* best_state); + +#endif /* SRSLTE_VITERBI37_H_ */ diff --git a/lib/src/phy/mimo/layermap.c b/lib/src/phy/mimo/layermap.c index fc2ac1a0d..3af86b1a3 100644 --- a/lib/src/phy/mimo/layermap.c +++ b/lib/src/phy/mimo/layermap.c @@ -53,7 +53,7 @@ int srslte_layermap_multiplex(cf_t* d[SRSLTE_MAX_CODEWORDS], { if (nof_cw == nof_layers) { for (int i = 0; i < nof_cw; i++) { - srs_vec_cf_cpy(d[i], x[i], (uint32_t)nof_symbols[0]); + srs_vec_cf_copy(x[i], d[i], (uint32_t)nof_symbols[0]); } return nof_symbols[0]; } else if (nof_cw == 1) { diff --git a/lib/src/phy/mimo/precoding.c b/lib/src/phy/mimo/precoding.c index d72801cf6..5c491e3f8 100644 --- a/lib/src/phy/mimo/precoding.c +++ b/lib/src/phy/mimo/precoding.c @@ -1889,16 +1889,16 @@ int srslte_predecoding_type(cf_t* y[SRSLTE_MAX_PORTS], if (nof_ports > SRSLTE_MAX_PORTS) { ERROR("Maximum number of ports is %d (nof_ports=%d)\n", SRSLTE_MAX_PORTS, nof_ports); - return -1; + return SRSLTE_ERROR; } if (nof_layers > SRSLTE_MAX_LAYERS) { ERROR("Maximum number of layers is %d (nof_layers=%d)\n", SRSLTE_MAX_LAYERS, nof_layers); - return -1; + return SRSLTE_ERROR; } switch (type) { case SRSLTE_TXSCHEME_CDD: - if (nof_layers >= 2 && nof_layers <= 4) { + if (nof_layers == 2) { switch (mimo_decoder) { case SRSLTE_MIMO_DECODER_ZF: return srslte_predecoding_ccd_zf(y, h, x, csi, nof_rxant, nof_ports, nof_layers, nof_symbols, scaling); @@ -1908,9 +1908,9 @@ int srslte_predecoding_type(cf_t* y[SRSLTE_MAX_PORTS], } } else { ERROR("Invalid number of layers %d\n", nof_layers); - return -1; + return SRSLTE_ERROR; } - return -1; + return SRSLTE_ERROR; case SRSLTE_TXSCHEME_PORT0: if (nof_ports == 1 && nof_layers == 1) { return srslte_predecoding_single_multi(y, h[0], x[0], csi, nof_rxant, nof_symbols, scaling, noise_estimate); @@ -1918,14 +1918,14 @@ int srslte_predecoding_type(cf_t* y[SRSLTE_MAX_PORTS], ERROR("Number of ports and layers must be 1 for transmission on single antenna ports (%d, %d)\n", nof_ports, nof_layers); - return -1; + return SRSLTE_ERROR; } case SRSLTE_TXSCHEME_DIVERSITY: if (nof_ports == nof_layers) { return srslte_predecoding_diversity_multi(y, h, x, csi, nof_rxant, nof_ports, nof_symbols, scaling); } else { ERROR("Error number of layers must equal number of ports in transmit diversity\n"); - return -1; + return SRSLTE_ERROR; } case SRSLTE_TXSCHEME_SPATIALMUX: return srslte_predecoding_multiplex( diff --git a/lib/src/phy/modem/hard_demod_lte.c b/lib/src/phy/modem/hard_demod_lte.c index c5f4e19ac..a5ecb793b 100644 --- a/lib/src/phy/modem/hard_demod_lte.c +++ b/lib/src/phy/modem/hard_demod_lte.c @@ -19,6 +19,9 @@ * */ +#ifndef SRSLTE_HARD_DEMOD_LTE_H_ +#define SRSLTE_HARD_DEMOD_LTE_H_ + #include #include #include @@ -280,4 +283,6 @@ inline void hard_qam256_demod(const cf_t* in, uint8_t* out, uint32_t N) out[8 * s + 7] = 0x0; } } -} \ No newline at end of file +} + +#endif /* SRSLTE_HARD_DEMOD_LTE_H_ */ \ No newline at end of file diff --git a/lib/src/phy/modem/lte_tables.h b/lib/src/phy/modem/lte_tables.h index cb22db57b..6ea82d141 100644 --- a/lib/src/phy/modem/lte_tables.h +++ b/lib/src/phy/modem/lte_tables.h @@ -18,6 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ +#ifndef SRSLTE_LTE_TABLES_H_ +#define SRSLTE_LTE_TABLES_H_ #include @@ -54,3 +56,5 @@ void set_16QAMtable(cf_t* table); void set_64QAMtable(cf_t* table); void set_256QAMtable(cf_t* table); + +#endif /* SRSLTE_LTE_TABLES_H_ */ diff --git a/lib/src/phy/phch/npbch.c b/lib/src/phy/phch/npbch.c index c2dfef63a..cb06a4aa0 100644 --- a/lib/src/phy/phch/npbch.c +++ b/lib/src/phy/phch/npbch.c @@ -517,7 +517,7 @@ int srslte_npbch_decode_frame(srslte_npbch_t* q, uint32_t nof_bits, uint32_t nof_ports) { - memcpy(&q->temp[dst * nof_bits], &q->llr[src * nof_bits], n * nof_bits * sizeof(float)); + srs_vec_f_copy(&q->temp[dst * nof_bits], &q->llr[src * nof_bits], n * nof_bits); // descramble srslte_scrambling_f_offset(&q->seq, &q->temp[dst * nof_bits], dst * nof_bits, n * nof_bits); diff --git a/lib/src/phy/phch/pbch.c b/lib/src/phy/phch/pbch.c index 48fb191b3..0f9e84805 100644 --- a/lib/src/phy/phch/pbch.c +++ b/lib/src/phy/phch/pbch.c @@ -401,7 +401,7 @@ int decode_frame(srslte_pbch_t* q, uint32_t src, uint32_t dst, uint32_t n, uint3 int j; if (dst + n <= 4 && src + n <= 4) { - memcpy(&q->temp[dst * nof_bits], &q->llr[src * nof_bits], n * nof_bits * sizeof(float)); + srs_vec_f_copy(&q->temp[dst * nof_bits], &q->llr[src * nof_bits], n * nof_bits); /* descramble */ srslte_scrambling_f_offset(&q->seq, &q->temp[dst * nof_bits], dst * nof_bits, n * nof_bits); diff --git a/lib/src/phy/phch/prb_dl.h b/lib/src/phy/phch/prb_dl.h index 3c85768ee..68d17e552 100644 --- a/lib/src/phy/phch/prb_dl.h +++ b/lib/src/phy/phch/prb_dl.h @@ -18,6 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ +#ifndef SRSLTE_PRB_DL_H_ +#define SRSLTE_PRB_DL_H_ #include "srslte/config.h" @@ -25,3 +27,5 @@ void prb_cp_ref(cf_t** input, cf_t** output, int offset, int nof_refs, int nof_i void prb_cp(cf_t** input, cf_t** output, int nof_prb); void prb_cp_half(cf_t** input, cf_t** output, int nof_prb); void prb_put_ref_(cf_t** input, cf_t** output, int offset, int nof_refs, int nof_intervals); + +#endif /* SRSLTE_PRB_DL_H_ */ diff --git a/lib/src/phy/phch/sch.c b/lib/src/phy/phch/sch.c index dffad4d88..492cd74b7 100644 --- a/lib/src/phy/phch/sch.c +++ b/lib/src/phy/phch/sch.c @@ -1251,7 +1251,7 @@ int srslte_ulsch_encode(srslte_sch_t* q, srslte_bit_pack_vector(q->temp_g_bits, g_bits, Q_prime_cqi * Qm); // Reset the buffer because will be reused in ulsch_interleave - bzero(q->temp_g_bits, Q_prime_cqi * Qm); + srslte_vec_u8_zero(q->temp_g_bits, Q_prime_cqi * Qm); } e_offset += Q_prime_cqi * Qm; diff --git a/lib/src/phy/phch/tbs_tables.h b/lib/src/phy/phch/tbs_tables.h index d6946308b..b6964e2ac 100644 --- a/lib/src/phy/phch/tbs_tables.h +++ b/lib/src/phy/phch/tbs_tables.h @@ -19,6 +19,9 @@ * */ +#ifndef SRSLTE_TBS_TABLES_H_ +#define SRSLTE_TBS_TABLES_H_ + /* Modulation and TBS index table for PDSCH from 3GPP TS 36.213 v10.3.0 table 7.1.7.1-1 */ static const int dl_mcs_tbs_idx_table[29] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; @@ -266,3 +269,5 @@ static const int tbs_table[SRSLTE_RA_NOF_TBS_IDX][110] = { 63776, 63776, 66592, 66592, 68808, 68808, 71112, 71112, 71112, 73712, 75376, 76208, 76208, 76208, 78704, 78704, 81176, 81176, 81176, 81176, 84760, 84760, 84760, 87936, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 93800, 97896, 97896, 97896, 97896, 97896, 97896, 97896, 97896, 97896, 97896, 97896, 97896, 97896}}; + +#endif /* SRSLTE_TBS_TABLES_H_ */ diff --git a/lib/src/phy/rf/rf_helper.h b/lib/src/phy/rf/rf_helper.h index ebce5373a..aea03d90f 100644 --- a/lib/src/phy/rf/rf_helper.h +++ b/lib/src/phy/rf/rf_helper.h @@ -18,6 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ +#ifndef SRSLTE_RF_HELPER_H_ +#define SRSLTE_RF_HELPER_H_ // A bunch of helper functions to process device arguments @@ -109,4 +111,6 @@ static inline int parse_uint32(char* args, const char* config_arg_base, int chan *value = tmp_value; return ret; -} \ No newline at end of file +} + +#endif /* SRSLTE_RF_HELPER_H_ */ diff --git a/lib/src/phy/rf/rf_soapy_imp.h b/lib/src/phy/rf/rf_soapy_imp.h index 455d23493..58907560d 100644 --- a/lib/src/phy/rf/rf_soapy_imp.h +++ b/lib/src/phy/rf/rf_soapy_imp.h @@ -19,6 +19,9 @@ * */ +#ifndef SRSLTE_RF_SOAPY_IMP_H_ +#define SRSLTE_RF_SOAPY_IMP_H_ + #include "srslte/config.h" #include "srslte/phy/rf/rf.h" #include @@ -98,3 +101,5 @@ int rf_soapy_send_timed_multi(void* h, bool blocking, bool is_start_of_burst, bool is_end_of_burst); + +#endif /* SRSLTE_RF_SOAPY_IMP_H_ */ diff --git a/lib/src/phy/rf/rf_uhd_imp.h b/lib/src/phy/rf/rf_uhd_imp.h index 33c838c58..9a37f9b7c 100644 --- a/lib/src/phy/rf/rf_uhd_imp.h +++ b/lib/src/phy/rf/rf_uhd_imp.h @@ -18,6 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ +#ifndef SRSLTE_RF_UHD_IMP_H_ +#define SRSLTE_RF_UHD_IMP_H_ #include #include @@ -102,3 +104,5 @@ SRSLTE_API int rf_uhd_send_timed_multi(void* h, bool blocking, bool is_start_of_burst, bool is_end_of_burst); + +#endif /* SRSLTE_RF_UHD_IMP_H_ */ diff --git a/lib/src/phy/rf/rf_zmq_imp.c b/lib/src/phy/rf/rf_zmq_imp.c index 395b7645f..11f478802 100644 --- a/lib/src/phy/rf/rf_zmq_imp.c +++ b/lib/src/phy/rf/rf_zmq_imp.c @@ -379,8 +379,6 @@ int rf_zmq_open_multi(char* args, void** h, uint32_t nof_channels) int rf_zmq_close(void* h) { - rf_zmq_stop_rx_stream(h); - rf_zmq_handler_t* handler = (rf_zmq_handler_t*)h; rf_zmq_info(handler->id, "Closing ...\n"); @@ -705,7 +703,7 @@ int rf_zmq_recv_with_time_multi(void* h, } } #endif // ZMQ_MONITOR - if (n > 0) { + if (n > SRSLTE_SUCCESS) { // No error count[i] += n; } else if (n == SRSLTE_ERROR_TIMEOUT) { @@ -713,7 +711,7 @@ int rf_zmq_recv_with_time_multi(void* h, if (handler->receiver[i].fail_on_disconnect) { goto clean_exit; } - } else if (n > 0) { + } else if (n < SRSLTE_SUCCESS) { // Other error, exit fprintf(stderr, "Error: receiving data.\n"); goto clean_exit; diff --git a/lib/src/phy/rf/rf_zmq_imp.h b/lib/src/phy/rf/rf_zmq_imp.h index b313ceb64..afd96c515 100644 --- a/lib/src/phy/rf/rf_zmq_imp.h +++ b/lib/src/phy/rf/rf_zmq_imp.h @@ -19,6 +19,9 @@ * */ +#ifndef SRSLTE_RF_ZMQ_IMP_H_ +#define SRSLTE_RF_ZMQ_IMP_H_ + #include #include @@ -96,3 +99,5 @@ SRSLTE_API int rf_zmq_send_timed_multi(void* h, bool blocking, bool is_start_of_burst, bool is_end_of_burst); + +#endif /* SRSLTE_RF_ZMQ_IMP_H_ */ diff --git a/lib/src/phy/rf/rf_zmq_imp_tx.c b/lib/src/phy/rf/rf_zmq_imp_tx.c index de0f14907..c68076ac5 100644 --- a/lib/src/phy/rf/rf_zmq_imp_tx.c +++ b/lib/src/phy/rf/rf_zmq_imp_tx.c @@ -138,7 +138,7 @@ static int _rf_zmq_tx_baseband(rf_zmq_tx_t* q, cf_t* buffer, uint32_t nsamples) // Send base-band if request was received if (n > 0) { - n = zmq_send(q->sock, buf, sample_sz * nsamples, 0); + n = zmq_send(q->sock, buf, (size_t)sample_sz * nsamples, 0); if (n < 0) { if (rf_zmq_handle_error(q->id, "tx baseband send")) { n = SRSLTE_ERROR; diff --git a/lib/src/phy/rf/uhd_c_api.h b/lib/src/phy/rf/uhd_c_api.h index 0ff340457..ec454cc30 100644 --- a/lib/src/phy/rf/uhd_c_api.h +++ b/lib/src/phy/rf/uhd_c_api.h @@ -18,6 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ +#ifndef SRSLTE_UHD_C_API_C_ +#define SRSLTE_UHD_C_API_C_ #include "srslte/config.h" #include "srslte/phy/rf/rf.h" @@ -30,3 +32,5 @@ SRSLTE_API void uhd_tx_metadata_set_start(uhd_tx_metadata_handle* md, bool is_st SRSLTE_API void uhd_tx_metadata_set_has_time_spec(uhd_tx_metadata_handle* md, bool has_time_spec); SRSLTE_API void uhd_tx_metadata_set_end(uhd_tx_metadata_handle* md, bool is_end_of_burst); SRSLTE_API void uhd_tx_metadata_add_time_spec(uhd_tx_metadata_handle* md, double frac_secs); + +#endif /* SRSLTE_UHD_C_API_C_ */ diff --git a/lib/src/phy/utils/vector.c b/lib/src/phy/utils/vector.c index 283a34743..07b031c7b 100644 --- a/lib/src/phy/utils/vector.c +++ b/lib/src/phy/utils/vector.c @@ -200,6 +200,21 @@ void srslte_vec_f_zero(float* ptr, uint32_t nsamples) memset(ptr, 0, sizeof(float) * nsamples); } +void srs_vec_cf_copy(cf_t* dst, const cf_t* src, uint32_t len) +{ + srslte_vec_cp_simd(src, dst, len); +} + +void srs_vec_f_copy(float* dst, const float* src, uint32_t len) +{ + memcpy(dst, src, sizeof(float) * len); +} + +void srs_vec_u8_copy(uint8_t* dst, const uint8_t* src, uint32_t len) +{ + memcpy(dst, src, sizeof(uint8_t) * len); +} + void* srslte_vec_realloc(void* ptr, uint32_t old_size, uint32_t new_size) { #ifndef LV_HAVE_SSE @@ -627,11 +642,6 @@ void srslte_vec_quant_sus(const int16_t* in, } } -void srs_vec_cf_cpy(const cf_t* src, cf_t* dst, int len) -{ - srslte_vec_cp_simd(src, dst, len); -} - void srslte_vec_interleave(const cf_t* x, const cf_t* y, cf_t* z, const int len) { srslte_vec_interleave_simd(x, y, z, len); diff --git a/lib/src/upper/rlc_am_lte.cc b/lib/src/upper/rlc_am_lte.cc index 1014131a7..a039b06a5 100644 --- a/lib/src/upper/rlc_am_lte.cc +++ b/lib/src/upper/rlc_am_lte.cc @@ -2081,7 +2081,7 @@ int rlc_am_write_status_pdu(rlc_status_pdu_t* status, uint8_t* payload) bool rlc_am_is_valid_status_pdu(const rlc_status_pdu_t& status) { - for (uint16_t i = 0; i < status.N_nack; ++i) { + for (uint32_t i = 0; i < status.N_nack; ++i) { if (status.nacks[i].nack_sn == status.ack_sn) { return false; } diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index 748746f0e..9bf27fccc 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -586,9 +586,11 @@ void rrc::log_neighbour_cells() int n = 0; n += snprintf(ordered, MAX_STR_LEN, "[%s", neighbour_cells[0]->to_string().c_str()); for (uint32_t i = 1; i < neighbour_cells.size(); i++) { - if (MAX_STR_LEN - n > 0) { // make sure there is still room left - int m = snprintf(&ordered[n], MAX_STR_LEN - n, " | %s", neighbour_cells[i]->to_string().c_str()); - n += m; + if (n < MAX_STR_LEN) { // make sure there is still room left + int m = snprintf(&ordered[n], (size_t)MAX_STR_LEN - n, " | %s", neighbour_cells[i]->to_string().c_str()); + if (m > 0) { + n += m; + } } } rrc_log->info("Neighbours: %s]\n", ordered); diff --git a/srsue/src/stack/upper/pcsc_usim.cc b/srsue/src/stack/upper/pcsc_usim.cc index 7c85bc162..a28aa8f85 100644 --- a/srsue/src/stack/upper/pcsc_usim.cc +++ b/srsue/src/stack/upper/pcsc_usim.cc @@ -932,7 +932,7 @@ int pcsc_usim::scard::get_imsi(char* imsi, size_t* len) imsilen = (blen - 2) * 2 + 1; log->debug("SCARD: IMSI file length=%ld imsilen=%ld\n", (long)blen, (long)imsilen); - if (blen < 2 || imsilen > *len) { + if (imsilen > *len) { *len = imsilen; return -4; }