Change in libosmocore[master]: Make gcc 11.1.0 false positivies happy

laforge gerrit-no-reply at lists.osmocom.org
Fri Jul 16 16:01:30 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/24948 )

Change subject: Make gcc 11.1.0 false positivies happy
......................................................................

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
---
M src/gsm/gsm48.c
M src/socket.c
2 files changed, 11 insertions(+), 12 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index ae1a21b..44ce776 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -601,8 +601,8 @@
 {
 	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 @@
 			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 @@
 		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 34972b8..19d48e4 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -894,7 +894,9 @@
 		   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)) {

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24948
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I8aacfbc21e23f63a65e8baee3fd536a1fe1bdd8a
Gerrit-Change-Number: 24948
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210716/a8000fb3/attachment.htm>


More information about the gerrit-log mailing list