]> git.saurik.com Git - apple/libinfo.git/blobdiff - rpc.subproj/xdr_array.c
Libinfo-392.tar.gz
[apple/libinfo.git] / rpc.subproj / xdr_array.c
index 734f3b06afcaf6b65f3575834d6cedc092d9933f..7b82e3e309efc5648ec063ae0fdc6ecd31c78b98 100644 (file)
@@ -21,6 +21,9 @@
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
+
+/*     $NetBSD: xdr_array.c,v 1.12 2000/01/22 22:19:18 mycroft Exp $   */
+
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
- * 
+ *
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-/*static char *sccsid = "from: @(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
-/*static char *sccsid = "from: @(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC";*/
-static char *rcsid = "$Id: xdr_array.c,v 1.4 2003/06/23 17:24:59 majka Exp $";
+static char *sccsid = "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";
+static char *sccsid = "@(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC";
 #endif
+#include <sys/cdefs.h>
 
 /*
  * xdr_array.c, Generic XDR routines impelmentation.
@@ -65,15 +68,15 @@ static char *rcsid = "$Id: xdr_array.c,v 1.4 2003/06/23 17:24:59 majka Exp $";
  * arrays.  See xdr.h for more info on the interface to xdr.
  */
 
+#include <err.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 
-#define LASTUNSIGNED   ((u_int)0-1)
-
-
 /*
  * XDR an array of arbitrary elements
  * *addrp is a pointer to the array, *sizep is the number of elements.
@@ -83,25 +86,26 @@ static char *rcsid = "$Id: xdr_array.c,v 1.4 2003/06/23 17:24:59 majka Exp $";
  */
 bool_t
 xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
-       register XDR *xdrs;
+       XDR *xdrs;
        caddr_t *addrp;         /* array pointer */
        u_int *sizep;           /* number of elements */
        u_int maxsize;          /* max numberof elements */
        u_int elsize;           /* size in bytes of each element */
        xdrproc_t elproc;       /* xdr routine to handle each element */
 {
-       register u_int i;
-       register caddr_t target = *addrp;
-       register u_int c;  /* the actual element count */
-       register bool_t stat = TRUE;
-       register u_int nodesize;
+       u_int i;
+       caddr_t target = *addrp;
+       u_int c;  /* the actual element count */
+       bool_t stat = TRUE;
+       u_int nodesize;
 
        /* like strings, arrays are really counted arrays */
-       if (! xdr_u_int(xdrs, sizep)) {
+       if (!xdr_u_int(xdrs, sizep)) {
                return (FALSE);
        }
        c = *sizep;
-       if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
+       if ((c > maxsize || UINT_MAX/elsize < c) &&
+           (xdrs->x_op != XDR_FREE)) {
                return (FALSE);
        }
        nodesize = c * elsize;
@@ -117,24 +121,24 @@ xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
                                return (TRUE);
                        *addrp = target = mem_alloc(nodesize);
                        if (target == NULL) {
-                               (void) fprintf(stderr, 
-                                       "xdr_array: out of memory\n");
+                               warnx("xdr_array: out of memory");
                                return (FALSE);
                        }
-                       bzero(target, nodesize);
+                       memset(target, 0, nodesize);
                        break;
 
                case XDR_FREE:
                        return (TRUE);
 
-               default: break;
+               case XDR_ENCODE:
+                       break;
        }
        
        /*
         * now we xdr each element of array
         */
        for (i = 0; (i < c) && stat; i++) {
-               stat = (*elproc)(xdrs, target, LASTUNSIGNED);
+               stat = (*elproc)(xdrs, target);
                target += elsize;
        }
 
@@ -160,22 +164,21 @@ xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
  */
 bool_t
 xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
-       register XDR *xdrs;
-       register char *basep;
-       register u_int nelem;
-       register u_int elemsize;
-       register xdrproc_t xdr_elem;    
+       XDR *xdrs;
+       char *basep;
+       u_int nelem;
+       u_int elemsize;
+       xdrproc_t xdr_elem;     
 {
-       register u_int i;
-       register char *elptr;
+       u_int i;
+       char *elptr;
 
        elptr = basep;
        for (i = 0; i < nelem; i++) {
-               if (! (*xdr_elem)(xdrs, elptr, LASTUNSIGNED)) {
+               if (!(*xdr_elem)(xdrs, elptr)) {
                        return(FALSE);
                }
                elptr += elemsize;
        }
        return(TRUE);   
 }
-