aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2021-07-15 13:08:08 +0200
committerlaforge <laforge@osmocom.org>2021-07-16 16:01:30 +0000
commit6fe865daae9dd1823eb98c819d4f99b4f0d5ac23 (patch)
tree2ba31c7054b9e30ac1ee2a398e3e7d17aaa20e4f
parent8a482fd0a85cba32e8cfb484e3a3f4cbaf4eb894 (diff)
Make gcc 11.1.0 false positivies happy
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
-rw-r--r--src/gsm/gsm48.c19
-rw-r--r--src/socket.c4
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)) {