diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-12-12 16:49:33 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-12-12 17:03:09 -0800 |
commit | 01834e99e461e2a8354f3b4aef7f14c5e83fa255 (patch) | |
tree | ee2d1871eeb757d272001fad439a3ade6f06fd2d | |
parent | 020d83d361b0ab54ac962e97b12935be785f9a67 (diff) |
os/access.c: replace acmp & acopy macros with memcmp & memcpy calls
No need to cast to char * now that all supported platforms use C89-standard
void * argument types, so just drop the casts from acmp & acopy macros,
which clears the gcc warnings for places const pointers were cast non-const:
access.c: In function 'DefineSelf':
access.c:786:3: warning: cast discards qualifiers from pointer target type
access.c:795:6: warning: cast discards qualifiers from pointer target type
access.c: In function 'NewHost':
access.c:1293:9: warning: cast discards qualifiers from pointer target type
access.c:1298:6: warning: cast discards qualifiers from pointer target type
access.c:1309:5: warning: cast discards qualifiers from pointer target type
Without the casts, acmp & acopy are just a funny way to write memcmp
& memmove, so drop the macros and inline the calls, taking care to
swap the first two arguments to memmove since it had swapped them.
Since all the calls to memmove end up being to non-overlapping memory
(mostly copying from an existing pointer to a newly allocated one),
replace those with memcpy.
And finally, don't actually call memcpy to copy 0 bytes from one place
to another, since that's just a waste of a perfectly good function call.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | os/access.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/os/access.c b/os/access.c index 0800c7f73..b609442de 100644 --- a/os/access.c +++ b/os/access.c @@ -176,12 +176,10 @@ SOFTWARE. Bool defeatAccessControl = FALSE; -#define acmp(a1, a2, len) memcmp((char *)(a1), (char *)(a2), len) -#define acopy(a1, a2, len) memmove((char *)(a2), (char *)(a1), len) #define addrEqual(fam, address, length, host) \ ((fam) == (host)->family &&\ (length) == (host)->len &&\ - !acmp (address, (host)->addr, length)) + !memcmp (address, (host)->addr, length)) static int ConvertAddr(struct sockaddr * /*saddr*/, int * /*len*/, @@ -371,13 +369,13 @@ DefineSelf (int fd) switch (hp->h_addrtype) { case AF_INET: inetaddr = (struct sockaddr_in *) (&(saddr.sa)); - acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length); + memcpy ( &(inetaddr->sin_addr), hp->h_addr, hp->h_length); len = sizeof(saddr.sa); break; #if defined(IPv6) && defined(AF_INET6) case AF_INET6: inet6addr = (struct sockaddr_in6 *) (&(saddr.sa)); - acopy ( hp->h_addr, &(inet6addr->sin6_addr), hp->h_length); + memcpy ( &(inet6addr->sin6_addr), hp->h_addr, hp->h_length); len = sizeof(saddr.in6); break; #endif @@ -398,7 +396,7 @@ DefineSelf (int fd) { host->family = family; host->len = len; - acopy ( addr, host->addr, len); + memcpy ( host->addr, addr, len); host->next = selfhosts; selfhosts = host; } @@ -448,7 +446,7 @@ DefineLocalHost: { host->family = FamilyLocalHost; host->len = 0; - acopy("", host->addr, 0); + /* Nothing to store in host->addr */ host->next = selfhosts; selfhosts = host; } @@ -585,7 +583,7 @@ DefineSelf (int fd) { host->family = family; host->len = len; - acopy(addr, host->addr, len); + memcpy(host->addr, addr, len); host->next = selfhosts; selfhosts = host; } @@ -717,7 +715,7 @@ DefineSelf (int fd) if (host != NULL) { host->family = family; host->len = len; - acopy(addr, host->addr, len); + memcpy(host->addr, addr, len); host->next = selfhosts; selfhosts = host; } @@ -792,7 +790,7 @@ DefineSelf (int fd) { host->family = FamilyLocalHost; host->len = 0; - acopy("", host->addr, 0); + /* Nothing to store in host->addr */ host->next = selfhosts; selfhosts = host; } @@ -821,7 +819,7 @@ AugmentSelf(pointer from, int len) return; host->family = family; host->len = len; - acopy(addr, host->addr, len); + memcpy(host->addr, addr, len); host->next = selfhosts; selfhosts = host; } @@ -1306,7 +1304,7 @@ NewHost (int family, return FALSE; host->family = family; host->len = len; - acopy(addr, host->addr, len); + memcpy(host->addr, addr, len); host->next = validhosts; validhosts = host; return TRUE; @@ -1400,7 +1398,7 @@ GetHosts ( ((xHostEntry *)ptr)->family = host->family; ((xHostEntry *)ptr)->length = len; ptr += sizeof(xHostEntry); - acopy (host->addr, ptr, len); + memcpy (ptr, host->addr, len); ptr += pad_to_int32(len); } } else { @@ -1763,7 +1761,7 @@ siHostnameAddrMatch(int family, pointer addr, int len, hostaddrlen = a->ai_addrlen; f = ConvertAddr(a->ai_addr,&hostaddrlen,&hostaddr); if ((f == family) && (len == hostaddrlen) && - (acmp (addr, hostaddr, len) == 0) ) { + (memcmp (addr, hostaddr, len) == 0) ) { res = TRUE; break; } @@ -1798,12 +1796,12 @@ siHostnameAddrMatch(int family, pointer addr, int len, struct sockaddr_in sin; sin.sin_family = hp->h_addrtype; - acopy ( *addrlist, &(sin.sin_addr), hp->h_length); + memcpy ( &(sin.sin_addr), *addrlist, hp->h_length); hostaddrlen = sizeof(sin); f = ConvertAddr ((struct sockaddr *)&sin, &hostaddrlen, &hostaddr); if ((f == family) && (len == hostaddrlen) && - (acmp (addr, hostaddr, len) == 0) ) { + (memcmp (addr, hostaddr, len) == 0) ) { res = TRUE; break; } |