Avoid casting gymnastics that lead to pointer aliasing by introducing an
inline function.
This commit is contained in:
parent
b9ba14885c
commit
fc8781bab9
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: clnt_vc.c,v 1.23 2013/05/07 21:08:45 christos Exp $ */
|
/* $NetBSD: clnt_vc.c,v 1.24 2013/10/17 23:58:05 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, Oracle America, Inc.
|
* Copyright (c) 2010, Oracle America, Inc.
|
||||||
|
@ -38,7 +38,7 @@ static char *sccsid = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
|
||||||
static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
|
static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
|
||||||
static char sccsid[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
|
static char sccsid[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: clnt_vc.c,v 1.23 2013/05/07 21:08:45 christos Exp $");
|
__RCSID("$NetBSD: clnt_vc.c,v 1.24 2013/10/17 23:58:05 christos Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -144,6 +144,33 @@ static cond_t *vc_cv;
|
||||||
#define __rpc_lock_value 0
|
#define __rpc_lock_value 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
htonlp(void *dst, const void *src)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
uint32_t tmp;
|
||||||
|
memcpy(&tmp, src, sizeof(tmp));
|
||||||
|
tmp = htonl(tmp);
|
||||||
|
memcpy(dst, &tmp, sizeof(tmp));
|
||||||
|
#else
|
||||||
|
/* We are aligned, so we think */
|
||||||
|
*(uint32_t *)dst = htonl(*(const uint32_t *)src);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
ntohlp(void *dst, const void *src)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
uint32_t tmp;
|
||||||
|
memcpy(&tmp, src, sizeof(tmp));
|
||||||
|
tmp = ntohl(tmp);
|
||||||
|
memcpy(dst, &tmp, sizeof(tmp));
|
||||||
|
#else
|
||||||
|
/* We are aligned, so we think */
|
||||||
|
*(uint32_t *)dst = htonl(*(const uint32_t *)src);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a client handle for a connection.
|
* Create a client handle for a connection.
|
||||||
|
@ -578,13 +605,12 @@ clnt_vc_control(
|
||||||
* first element in the call structure
|
* first element in the call structure
|
||||||
* This will get the xid of the PREVIOUS call
|
* This will get the xid of the PREVIOUS call
|
||||||
*/
|
*/
|
||||||
*(u_int32_t *)(void *)info =
|
ntohlp(info, &ct->ct_u.ct_mcalli);
|
||||||
ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli);
|
|
||||||
break;
|
break;
|
||||||
case CLSET_XID:
|
case CLSET_XID:
|
||||||
/* This will set the xid of the NEXT call */
|
/* This will set the xid of the NEXT call */
|
||||||
*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli =
|
htonlp(&ct->ct_u.ct_mcalli, (const char *)info +
|
||||||
htonl(*((u_int32_t *)(void *)info) + 1);
|
sizeof(uint32_t));
|
||||||
/* increment by 1 as clnt_vc_call() decrements once */
|
/* increment by 1 as clnt_vc_call() decrements once */
|
||||||
break;
|
break;
|
||||||
case CLGET_VERS:
|
case CLGET_VERS:
|
||||||
|
@ -594,15 +620,11 @@ clnt_vc_control(
|
||||||
* begining of the RPC header. MUST be changed if the
|
* begining of the RPC header. MUST be changed if the
|
||||||
* call_struct is changed
|
* call_struct is changed
|
||||||
*/
|
*/
|
||||||
*(u_int32_t *)(void *)info =
|
ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT);
|
||||||
ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
|
||||||
4 * BYTES_PER_XDR_UNIT));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLSET_VERS:
|
case CLSET_VERS:
|
||||||
*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info);
|
||||||
4 * BYTES_PER_XDR_UNIT) =
|
|
||||||
htonl(*(u_int32_t *)(void *)info);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLGET_PROG:
|
case CLGET_PROG:
|
||||||
|
@ -612,15 +634,11 @@ clnt_vc_control(
|
||||||
* begining of the RPC header. MUST be changed if the
|
* begining of the RPC header. MUST be changed if the
|
||||||
* call_struct is changed
|
* call_struct is changed
|
||||||
*/
|
*/
|
||||||
*(u_int32_t *)(void *)info =
|
ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT);
|
||||||
ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
|
||||||
3 * BYTES_PER_XDR_UNIT));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLSET_PROG:
|
case CLSET_PROG:
|
||||||
*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info);
|
||||||
3 * BYTES_PER_XDR_UNIT) =
|
|
||||||
htonl(*(u_int32_t *)(void *)info);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue