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
This commit is contained in:
Pau Espin 2021-07-15 13:08:08 +02:00 committed by laforge
parent 8a482fd0a8
commit 6fe865daae
2 changed files with 11 additions and 12 deletions

View File

@ -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,

View File

@ -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)) {