[PATCH] Fix xdrstdio_{get,put}long on bigendian, 64bit

Thorsten Kukuk kukuk@suse.de
Mon Mar 21 11:28:00 GMT 2005


Hi,

xdrstdio_putlong does not work on 64bit bigendian machines correct,
it access the wrong part of a long as integer.

Attached is a fix with a cleanup for xdrstdio_getlong, too.

  Thorsten
-- 
Thorsten Kukuk         http://www.suse.de/~kukuk/      kukuk@suse.de
SUSE LINUX Products GmbH       Maxfeldstr. 5       D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------
2005-03-21  Thorsten Kukuk  <kukuk@suse.de>

	* sunrpc/xdr_stdio.c (xdrstdio_getlong,xdrstdio_putlong):
	Convert correct between long/int on 64bit bigendian.

--- sunrpc/xdr_stdio.c
+++ sunrpc/xdr_stdio.c	2005/03/18 10:59:07
@@ -108,20 +108,20 @@
 static bool_t
 xdrstdio_getlong (XDR *xdrs, long *lp)
 {
-  int32_t mycopy;
+  u_int32_t mycopy;
 
-  if (fread ((caddr_t) & mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+  if (fread ((caddr_t) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
     return FALSE;
-  *lp = (int32_t) ntohl (mycopy);
+  *lp = (long) ntohl (mycopy);
   return TRUE;
 }
 
 static bool_t
 xdrstdio_putlong (XDR *xdrs, const long *lp)
 {
-  long mycopy = htonl (*lp);
-  lp = &mycopy;
-  if (fwrite ((caddr_t) lp, 4, 1, (FILE *) xdrs->x_private) != 1)
+  int32_t mycopy = htonl ((u_int32_t) *lp);
+
+  if (fwrite ((caddr_t) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
     return FALSE;
   return TRUE;
 }


More information about the Libc-alpha mailing list