[PATCH 07/25] os/access.c: replace acmp & acopy macros with memcmp & memcpy calls
Alan Coopersmith
alan.coopersmith at oracle.com
Sun Dec 11 10:16:20 PST 2011
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 at oracle.com>
---
os/access.c | 30 ++++++++++++++----------------
1 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/os/access.c b/os/access.c
index 0800c7f..b609442 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;
}
--
1.7.3.2
More information about the xorg-devel
mailing list