Incomplete patch to fix build with top-of-tree GCC

Message ID 1431983665.16668.28.camel@ubuntu-sellcey
State Committed
Headers

Commit Message

Steve Ellcey May 18, 2015, 9:14 p.m. UTC
  Paul and Carlos,

I updated Paul's patch to fix the rest of rcmd.c and verified that it
builds now with the latest GCC.  Is this patch OK to checkin?


2015-05-15  Paul Eggert  <eggert@cs.ucla.edu>
	    Steve Ellcey  <sellcey@imgtec.com>

	* inet/rcmd.c (rresvport_af): Change ss to anonymous union
	in order to avoid strict alias warnings.
	(iruserok_af): Ditto for ra.
  

Comments

Roland McGrath May 18, 2015, 10 p.m. UTC | #1
> -	struct sockaddr_storage ss;
> +	union {
> +	  struct sockaddr generic;
> +	  struct sockaddr_in in;
> +	  struct sockaddr_in6 in6;
> +	} ss;

Since we're not reformatting this file to GNU style (which would put the {
here on its own line), this should instead stick with the existing (BSD)
style of the rest of the file, which is TAB indentation.  (These lines
appear twice in the patch.  Fix both places.)

With that formatting fix, this looks fine to me.
  
Carlos O'Donell May 20, 2015, 2:32 a.m. UTC | #2
On 05/18/2015 05:14 PM, Steve Ellcey wrote:
> Paul and Carlos,
> 
> I updated Paul's patch to fix the rest of rcmd.c and verified that it
> builds now with the latest GCC.  Is this patch OK to checkin?
> 
> 
> 2015-05-15  Paul Eggert  <eggert@cs.ucla.edu>
> 	    Steve Ellcey  <sellcey@imgtec.com>
> 
> 	* inet/rcmd.c (rresvport_af): Change ss to anonymous union
> 	in order to avoid strict alias warnings.
> 	(iruserok_af): Ditto for ra.

Thanks for fixing this. It's a pleasure to see this stuff get fixed.

c.
  

Patch

diff --git a/inet/rcmd.c b/inet/rcmd.c
index acacaa0..a2c7c8e 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -374,7 +374,11 @@  rresvport_af(alport, family)
 	int *alport;
 	sa_family_t family;
 {
-	struct sockaddr_storage ss;
+	union {
+	  struct sockaddr generic;
+	  struct sockaddr_in in;
+	  struct sockaddr_in6 in6;
+	} ss;
 	int s;
 	size_t len;
 	uint16_t *sport;
@@ -382,11 +386,11 @@  rresvport_af(alport, family)
 	switch(family){
 	case AF_INET:
 		len = sizeof(struct sockaddr_in);
-		sport = &((struct sockaddr_in *)&ss)->sin_port;
+		sport = &ss.in.sin_port;
 		break;
 	case AF_INET6:
 		len = sizeof(struct sockaddr_in6);
-		sport = &((struct sockaddr_in6 *)&ss)->sin6_port;
+		sport = &ss.in6.sin6_port;
 		break;
 	default:
 		__set_errno (EAFNOSUPPORT);
@@ -398,9 +402,9 @@  rresvport_af(alport, family)
 
 	memset (&ss, '\0', sizeof(ss));
 #ifdef SALEN
-	ss.__ss_len = len;
+	ss.generic.__ss_len = len;
 #endif
-	ss.ss_family = family;
+	ss.generic.sa_family = family;
 
 	/* Ignore invalid values.  */
 	if (*alport < IPPORT_RESERVED / 2)
@@ -411,7 +415,7 @@  rresvport_af(alport, family)
 	int start = *alport;
 	do {
 		*sport = htons((uint16_t) *alport);
-		if (__bind(s, (struct sockaddr *)&ss, len) >= 0)
+		if (__bind(s, &ss.generic, len) >= 0)
 			return s;
 		if (errno != EADDRINUSE) {
 			(void)__close(s);
@@ -604,27 +608,29 @@  iruserok_af (raddr, superuser, ruser, luser, af)
      const char *ruser, *luser;
      sa_family_t af;
 {
-  struct sockaddr_storage ra;
+  union {
+    struct sockaddr generic;
+    struct sockaddr_in in;
+    struct sockaddr_in6 in6;
+  } ra;
   size_t ralen;
 
   memset (&ra, '\0', sizeof(ra));
   switch (af){
   case AF_INET:
-    ra.ss_family = AF_INET;
-    memcpy (&(((struct sockaddr_in *)&ra)->sin_addr), raddr,
-	    sizeof(struct in_addr));
+    ra.in.sin_family = AF_INET;
+    memcpy (&ra.in.sin_addr, raddr, sizeof(struct in_addr));
     ralen = sizeof(struct sockaddr_in);
     break;
   case AF_INET6:
-    ra.ss_family = AF_INET6;
-    memcpy (&(((struct sockaddr_in6 *)&ra)->sin6_addr), raddr,
-	    sizeof(struct in6_addr));
+    ra.in6.sin6_family = AF_INET6;
+    memcpy (&ra.in6.sin6_addr, raddr, sizeof(struct in6_addr));
     ralen = sizeof(struct sockaddr_in6);
     break;
   default:
     return 0;
   }
-  return ruserok_sa ((struct sockaddr *)&ra, ralen, superuser, ruser, luser);
+  return ruserok_sa (&ra.generic, ralen, superuser, ruser, luser);
 }
 libc_hidden_def (iruserok_af)