Skip to contentSkip to conversation

inet_ntop.c: Work around GCC 4.6's detection of uninitialized variables

PATCH In review Sebastian Schuberth 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inet_ntop.c: Work around GCC 4.6's detection of uninitialized variables

GCC 4.6 claims that

error: 'best.len' may be used uninitialized in this function

so silence that warning which is treated as an error by also initializing the "len" members of the struct.

---
 compat/inet_ntop.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
compat/inet_ntop.c +2 -0
index ea249c6..60b5a1d 100644
@@ -98,7 +98,9 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
 	for (i = 0; i < NS_IN6ADDRSZ; i++)
 		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
 	best.base = -1;
+	best.len = 0;
 	cur.base = -1;
+	cur.len = 0;
 	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
 		if (words[i] == 0) {
 			if (cur.base == -1)
Signature · 1 line
1.7.7.msysgit.1
#1 lore raw
Quoted 17 lines · Sebastian Schuberth

GCC 4.6 claims that

error: 'best.len' may be used uninitialized in this function

so silence that warning which is treated as an error by also initializing the "len" members of the struct.

---
 compat/inet_ntop.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
compat/inet_ntop.c +0 -0
index ea249c6..60b5a1d 100644

compat/inet_ntop.c inet_ntop6(const u_char *src, char *dst, size_t size) · line 103

Quoted 6 lines
compat/inet_ntop.c +2 -0
@@ -98,7 +98,9 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
 	for (i = 0; i < NS_IN6ADDRSZ; i++)
 		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
 	best.base = -1;
+	best.len = 0;
 	cur.base = -1;
+	cur.len = 0;

It may be just the "taste" thing, but I wonder if

	best.base = -1;
        best.len = 0;
        cur = best;

might be easier on the eyes.

Will queue as-is anyway. Thanks.

Quoted 3 lines
compat/inet_ntop.c +0 -0
 	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
 		if (words[i] == 0) {
 			if (cur.base == -1)
#2 lore raw

GCC 4.6 claims that

error: 'best.len' may be used uninitialized in this function

so silence that warning which is treated as an error by also initializing the "len" members of the struct.

---
 compat/inet_ntop.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
compat/inet_ntop.c +2 -1
index ea249c6..9e9f6fb 100644
@@ -98,7 +98,8 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
 	for (i = 0; i < NS_IN6ADDRSZ; i++)
 		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
 	best.base = -1;
-	cur.base = -1;
+	best.len = 0;
+	cur = best;
 	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
 		if (words[i] == 0) {
 			if (cur.base == -1)
Signature · 1 line
1.7.7.msysgit.1