From fd01c44d4e69efaad3b18dfad3e7574621fb7956 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 14 Oct 2019 16:36:52 +0100 Subject: [PATCH] Fix compilation error on GCC 8.x due to usage of strncpy in zmq_imp_rx/tx. Fixed also order in which zmq object is zero'ed out. --- lib/src/phy/rf/rf_zmq_imp_rx.c | 7 ++++--- lib/src/phy/rf/rf_zmq_imp_trx.h | 5 +++-- lib/src/phy/rf/rf_zmq_imp_tx.c | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/src/phy/rf/rf_zmq_imp_rx.c b/lib/src/phy/rf/rf_zmq_imp_rx.c index 97d99b658..e1deda04f 100644 --- a/lib/src/phy/rf/rf_zmq_imp_rx.c +++ b/lib/src/phy/rf/rf_zmq_imp_rx.c @@ -100,12 +100,13 @@ int rf_zmq_rx_open(rf_zmq_rx_t* q, char* id, void* zmq_ctx, char* sock_args) int ret = SRSLTE_ERROR; if (q) { - // Copy id - strncpy(q->id, id, 16); - // Zero object bzero(q, sizeof(rf_zmq_tx_t)); + // Copy id + strncpy(q->id, id, ZMQ_ID_STRLEN - 1); + q->id[ZMQ_ID_STRLEN - 1] = '\0'; + // Create socket q->sock = zmq_socket(zmq_ctx, ZMQ_REQ); if (!q->sock) { diff --git a/lib/src/phy/rf/rf_zmq_imp_trx.h b/lib/src/phy/rf/rf_zmq_imp_trx.h index 2f6f8727f..f73961d35 100644 --- a/lib/src/phy/rf/rf_zmq_imp_trx.h +++ b/lib/src/phy/rf/rf_zmq_imp_trx.h @@ -38,9 +38,10 @@ #define ZMQ_MAX_BUFFER_SIZE (NSAMPLES2NBYTES(3072000)) // 10 subframes at 20 MHz #define ZMQ_TIMEOUT_MS (1000) #define ZMQ_BASERATE_DEFAULT_HZ (23040000) +#define ZMQ_ID_STRLEN 16 typedef struct { - char id[16]; + char id[ZMQ_ID_STRLEN]; void* sock; uint64_t nsamples; bool running; @@ -49,7 +50,7 @@ typedef struct { } rf_zmq_tx_t; typedef struct { - char id[16]; + char id[ZMQ_ID_STRLEN]; void* sock; uint64_t nsamples; bool running; diff --git a/lib/src/phy/rf/rf_zmq_imp_tx.c b/lib/src/phy/rf/rf_zmq_imp_tx.c index ad38d2e7e..71320fc08 100644 --- a/lib/src/phy/rf/rf_zmq_imp_tx.c +++ b/lib/src/phy/rf/rf_zmq_imp_tx.c @@ -36,12 +36,13 @@ int rf_zmq_tx_open(rf_zmq_tx_t* q, const char* id, void* zmq_ctx, char* sock_arg int ret = SRSLTE_ERROR; if (q) { - // Copy id - strncpy(q->id, id, 16); - // Zero object bzero(q, sizeof(rf_zmq_tx_t)); + // Copy id + strncpy(q->id, id, ZMQ_ID_STRLEN - 1); + q->id[ZMQ_ID_STRLEN - 1] = '\0'; + // Create socket q->sock = zmq_socket(zmq_ctx, ZMQ_REP); if (!q->sock) {