This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Incomplete patch to fix build with top-of-tree GCC
- From: Steve Ellcey <sellcey at imgtec dot com>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: Paul Eggert <eggert at cs dot ucla dot edu>, Joseph Myers <joseph at codesourcery dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 18 May 2015 14:14:25 -0700
- Subject: Re: Incomplete patch to fix build with top-of-tree GCC
- Authentication-results: sourceware.org; auth=none
- References: <1431708170 dot 16668 dot 8 dot camel at ubuntu-sellcey> <alpine dot DEB dot 2 dot 10 dot 1505151645070 dot 21212 at digraph dot polyomino dot org dot uk> <55565718 dot 6070107 at cs dot ucla dot edu> <5556C3E4 dot 1080108 at redhat dot com>
- Reply-to: <sellcey at imgtec dot com>
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.
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)