aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2021-07-15 14:34:35 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2021-07-15 14:39:39 +0200
commit890de986ce99079877f3c7202db5e0405309ff60 (patch)
tree024aef5f2af9d9ed3e8f7b5c92580779aa150a11
parent4f67a9bf4610c9e948f0d81f3b039f36675180a3 (diff)
Make gcc 11.1.0 false positivies happy
After my system's gcc was upgraded, I get false positivies like the one below: """ /git/osmo-pcu/src/gprs_bssgp_pcu.c: In function ‘ns_configure_nse’: /git/osmo-pcu/src/gprs_bssgp_pcu.c:1103:58: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 2 [-Werror=format-truncation=] 1103 | snprintf(name, sizeof(name), "pcu%d", i); | ^~ /git/osmo-pcu/src/gprs_bssgp_pcu.c:1103:54: note: directive argument in the range [-2147483648, 1] 1103 | snprintf(name, sizeof(name), "pcu%d", i); | ^~~~~~~ /git/osmo-pcu/src/gprs_bssgp_pcu.c:1103:25: note: ‘snprintf’ output between 5 and 15 bytes into a destination of size 5 1103 | snprintf(name, sizeof(name), "pcu%d", i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ In this case, i can't never take a value with more than 1 digit, but gcc seems to be unable to see that. Let's increase the buffer size a few bytes to make gcc happy, and make the variable unsigned since it never will get negative values. Next change is also a false positive, since variables are always initialized beforehand in the cod epaths where they are used: """ /git/osmo-pcu/src/bts.cpp: In function ‘int bts_rcv_rach(gprs_rlcmac_bts*, const rach_ind_params*)’: /git/osmo-pcu/src/bts.cpp:859:25: error: ‘ts_no’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 859 | uint8_t trx_no, ts_no; | ^~~~~ /git/osmo-pcu/src/bts.cpp:859:17: error: ‘trx_no’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 859 | uint8_t trx_no, ts_no; | ^~~~~~ """ Change-Id: I1362a335a0c761bde367dbc779de4afa88f13584
-rw-r--r--src/bts.cpp2
-rw-r--r--src/gprs_bssgp_pcu.c7
2 files changed, 5 insertions, 4 deletions
diff --git a/src/bts.cpp b/src/bts.cpp
index 95dde047..ee6b915a 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -856,7 +856,7 @@ int bts_rcv_rach(struct gprs_rlcmac_bts *bts, const struct rach_ind_params *rip)
struct chan_req_params chan_req = { 0 };
struct gprs_rlcmac_ul_tbf *tbf = NULL;
struct gprs_rlcmac_sba *sba;
- uint8_t trx_no, ts_no;
+ uint8_t trx_no = 0, ts_no = 0; /* initialize to avoid uninitialized false warnings on some gcc versions (11.1.0) */
uint32_t sb_fn = 0;
uint8_t usf = 7;
uint8_t tsc = 0;
diff --git a/src/gprs_bssgp_pcu.c b/src/gprs_bssgp_pcu.c
index 0e8e1459..e2f6f519 100644
--- a/src/gprs_bssgp_pcu.c
+++ b/src/gprs_bssgp_pcu.c
@@ -1075,12 +1075,13 @@ static int ns_configure_nse(struct gprs_rlcmac_bts *bts,
const uint16_t *nsvci,
uint16_t valid)
{
- int i, rc;
+ unsigned int i;
+ int rc;
uint16_t binds = 0;
bool nsvcs = false;
struct gprs_ns2_vc *nsvc;
struct gprs_ns2_vc_bind *bind[PCU_IF_NUM_NSVC] = { };
- char name[5];
+ char name[16];
bool sns_configured = false;
if (!valid)
@@ -1100,7 +1101,7 @@ static int ns_configure_nse(struct gprs_rlcmac_bts *bts,
continue;
if (!gprs_ns2_ip_bind_by_sockaddr(the_pcu->nsi, &local[i])) {
- snprintf(name, sizeof(name), "pcu%d", i);
+ snprintf(name, sizeof(name), "pcu%u", i);
rc = gprs_ns2_ip_bind(the_pcu->nsi, name, &local[i], 0, &bind[i]);
if (rc < 0) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to bind to %s\n", osmo_sockaddr_to_str(&local[i]));