From 6fe865daae9dd1823eb98c819d4f99b4f0d5ac23 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 15 Jul 2021 13:08:08 +0200 Subject: Make gcc 11.1.0 false positivies happy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After my system's gcc was upgraded, I get false positivies in a couple places. Let's initialize those to make gcc happy. """ /git/libosmocore/src/socket.c: In function ‘osmo_sock_init’: /git/libosmocore/src/socket.c:958:25: error: ‘sfd’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 958 | close(sfd); | ^~~~~~~~~~ /git/libosmocore/src/gsm/gsm48.c: In function ‘osmo_mobile_identity_decode’: /git/libosmocore/src/gsm/gsm48.c:690:20: error: ‘str_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 690 | if (rc < 1 || rc >= str_size) { | ~~~~~~~^~~~~~~~~~~~~~~~~ /git/libosmocore/src/gsm/gsm48.c:679:22: error: ‘str’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 679 | rc = osmo_bcd2str(str, str_size, mi_data, 1, 1 + nibbles_len, allow_hex); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ Change-Id: I8aacfbc21e23f63a65e8baee3fd536a1fe1bdd8a --- src/gsm/gsm48.c | 19 ++++++++----------- src/socket.c | 4 +++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c index ae1a21bd..44ce7767 100644 --- a/src/gsm/gsm48.c +++ b/src/gsm/gsm48.c @@ -601,8 +601,8 @@ int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t * { int rc; int nibbles_len; - char *str; - size_t str_size; + char *str = NULL; /* initialize to avoid uninitialized false warnings on some gcc versions (11.1.0) */ + size_t str_size = 0; /* initialize to avoid uninitialized false warnings on some gcc versions (11.1.0) */ if (!mi_data || mi_len < 1) return -EBADMSG; @@ -677,8 +677,12 @@ int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t * goto return_error; } rc = osmo_bcd2str(str, str_size, mi_data, 1, 1 + nibbles_len, allow_hex); - /* rc checked below */ - break; + /* check mi->str printing rc */ + if (rc < 1 || rc >= str_size) { + rc = -EBADMSG; + goto return_error; + } + return 0; default: /* Already handled above, but as future bug paranoia: */ @@ -686,13 +690,6 @@ int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t * goto return_error; } - /* check mi->str printing rc */ - if (rc < 1 || rc >= str_size) { - rc = -EBADMSG; - goto return_error; - } - return 0; - return_error: *mi = (struct osmo_mobile_identity){ .type = GSM_MI_TYPE_NONE, diff --git a/src/socket.c b/src/socket.c index 34972b88..19d48e4f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -894,7 +894,9 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto, const char *host, uint16_t port, unsigned int flags) { struct addrinfo *result, *rp; - int sfd, rc, on = 1; + int sfd = -1; /* initialize to avoid uninitialized false warnings on some gcc versions (11.1.0) */ + int on = 1; + int rc; if ((flags & (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) == (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) { -- cgit v1.2.3-59-g8ed1b