diff options
author | pfg <pfg@FreeBSD.org> | 2016-03-04 15:30:41 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2016-03-04 15:30:41 +0000 |
commit | 6ed428b4ed99e251a621853161e0391892d65b86 (patch) | |
tree | 92b9c118f6c2dca556f2636249f8e474739f268d /lib/libc/rpc | |
parent | dab3e49fbe54a9c9d5d0504e823078577e4a7bb4 (diff) | |
download | FreeBSD-src-6ed428b4ed99e251a621853161e0391892d65b86.zip FreeBSD-src-6ed428b4ed99e251a621853161e0391892d65b86.tar.gz |
Work around aliasing issues detected in modern GCC.
Avoid casting gymnastics that lead to pointer aliasing by introducing an
inline function as done in NetBSD (but without #if0'd WIP code).
Obtained from: NetBSD (CVS Rev. 1.24, 1.25)
Diffstat (limited to 'lib/libc/rpc')
-rw-r--r-- | lib/libc/rpc/clnt_vc.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/lib/libc/rpc/clnt_vc.c b/lib/libc/rpc/clnt_vc.c index aa16b96..8673a2b 100644 --- a/lib/libc/rpc/clnt_vc.c +++ b/lib/libc/rpc/clnt_vc.c @@ -502,6 +502,20 @@ clnt_vc_abort(CLIENT *cl) { } +static __inline void +htonlp(void *dst, const void *src, uint32_t incr) +{ + /* We are aligned, so we think */ + *(uint32_t *)dst = htonl(*(const uint32_t *)src + incr); +} + +static __inline void +ntohlp(void *dst, const void *src) +{ + /* We are aligned, so we think */ + *(uint32_t *)dst = htonl(*(const uint32_t *)src); +} + static bool_t clnt_vc_control(CLIENT *cl, u_int request, void *info) { @@ -576,14 +590,12 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info) * first element in the call structure * This will get the xid of the PREVIOUS call */ - *(u_int32_t *)info = - ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli); + ntohlp(info, &ct->ct_u.ct_mcalli); break; case CLSET_XID: /* This will set the xid of the NEXT call */ - *(u_int32_t *)(void *)&ct->ct_u.ct_mcalli = - htonl(*((u_int32_t *)info) + 1); /* increment by 1 as clnt_vc_call() decrements once */ + htonlp(&ct->ct_u.ct_mcalli, info, 1); break; case CLGET_VERS: /* @@ -592,15 +604,11 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info) * begining of the RPC header. MUST be changed if the * call_struct is changed */ - *(u_int32_t *)info = - ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 4 * BYTES_PER_XDR_UNIT)); + ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT); break; case CLSET_VERS: - *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 4 * BYTES_PER_XDR_UNIT) = - htonl(*(u_int32_t *)info); + htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0); break; case CLGET_PROG: @@ -610,15 +618,11 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info) * begining of the RPC header. MUST be changed if the * call_struct is changed */ - *(u_int32_t *)info = - ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 3 * BYTES_PER_XDR_UNIT)); + ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT); break; case CLSET_PROG: - *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 3 * BYTES_PER_XDR_UNIT) = - htonl(*(u_int32_t *)info); + htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0); break; default: |