Clean up some signed/unsigned issues in the XDR code.

Obtained from:	OpenBSD
This commit is contained in:
Jacques Vidrine 2003-03-07 13:19:40 +00:00
parent 5a42be36e3
commit d7f15c948f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=111962
4 changed files with 19 additions and 13 deletions

View File

@ -121,7 +121,7 @@ typedef struct __rpc_xdr {
char * x_public; /* users' data */
void * x_private; /* pointer to private data */
char * x_base; /* private used for position info */
int x_handy; /* extra private word */
u_int x_handy; /* extra private word */
} XDR;
/*

View File

@ -280,7 +280,7 @@ typedef struct {
caddr_t x_public; /* users' data */
caddr_t x_private; /* pointer to private data */
caddr_t x_base; /* private used for position info */
int x_handy; /* extra private word */
u_int x_handy; /* extra private word */
} XDR;
/*

View File

@ -126,8 +126,9 @@ xdrmem_getlong_aligned(xdrs, lp)
long *lp;
{
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
if (xdrs->x_handy < sizeof(int32_t))
return (FALSE);
xdrs->x_handy -= sizeof(int32_t);
*lp = ntohl(*(u_int32_t *)xdrs->x_private);
xdrs->x_private = (char *)xdrs->x_private + sizeof(int32_t);
return (TRUE);
@ -139,8 +140,9 @@ xdrmem_putlong_aligned(xdrs, lp)
const long *lp;
{
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
if (xdrs->x_handy < sizeof(int32_t))
return (FALSE);
xdrs->x_handy -= sizeof(int32_t);
*(u_int32_t *)xdrs->x_private = htonl((u_int32_t)*lp);
xdrs->x_private = (char *)xdrs->x_private + sizeof(int32_t);
return (TRUE);
@ -153,8 +155,9 @@ xdrmem_getlong_unaligned(xdrs, lp)
{
u_int32_t l;
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
if (xdrs->x_handy < sizeof(int32_t))
return (FALSE);
xdrs->x_handy -= sizeof(int32_t);
memmove(&l, xdrs->x_private, sizeof(int32_t));
*lp = ntohl(l);
xdrs->x_private = (char *)xdrs->x_private + sizeof(int32_t);
@ -168,8 +171,9 @@ xdrmem_putlong_unaligned(xdrs, lp)
{
u_int32_t l;
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
if (xdrs->x_handy < sizeof(int32_t))
return (FALSE);
xdrs->x_handy -= sizeof(int32_t);
l = htonl((u_int32_t)*lp);
memmove(xdrs->x_private, &l, sizeof(int32_t));
xdrs->x_private = (char *)xdrs->x_private + sizeof(int32_t);
@ -183,8 +187,9 @@ xdrmem_getbytes(xdrs, addr, len)
u_int len;
{
if ((xdrs->x_handy -= len) < 0)
if (xdrs->x_handy < len)
return (FALSE);
xdrs->x_handy -= len;
memmove(addr, xdrs->x_private, len);
xdrs->x_private = (char *)xdrs->x_private + len;
return (TRUE);
@ -197,8 +202,9 @@ xdrmem_putbytes(xdrs, addr, len)
u_int len;
{
if ((xdrs->x_handy -= len) < 0)
if (xdrs->x_handy < len)
return (FALSE);
xdrs->x_handy -= len;
memmove(xdrs->x_private, addr, len);
xdrs->x_private = (char *)xdrs->x_private + len;
return (TRUE);
@ -221,10 +227,10 @@ xdrmem_setpos(xdrs, pos)
char *newaddr = xdrs->x_base + pos;
char *lastaddr = (char *)xdrs->x_private + xdrs->x_handy;
if ((long)newaddr > (long)lastaddr)
if (newaddr > lastaddr)
return (FALSE);
xdrs->x_private = newaddr;
xdrs->x_handy = (int)((long)lastaddr - (long)newaddr);
xdrs->x_handy = (u_int)(lastaddr - newaddr); /* XXX sizeof(u_int) <? sizeof(ptrdiff_t) */
return (TRUE);
}

View File

@ -60,7 +60,7 @@ static bool_t
x_putbytes(xdrs, bp, len)
XDR *xdrs;
char *bp;
int len;
u_int len;
{
xdrs->x_handy += len;
return (TRUE);
@ -86,7 +86,7 @@ x_setpostn(xdrs, pos)
static int32_t *
x_inline(xdrs, len)
XDR *xdrs;
long len;
u_int len;
{
if (len == 0) {
return (NULL);
@ -94,7 +94,7 @@ x_inline(xdrs, len)
if (xdrs->x_op != XDR_ENCODE) {
return (NULL);
}
if (len < (long) xdrs->x_base) {
if (len < (u_int)xdrs->x_base) {
/* x_private was already allocated */
xdrs->x_handy += len;
return ((int32_t *) xdrs->x_private);