Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Tom Quinn <trq@hermes.astro.washington.edu>
Subject: bug in xdr_double() on alpha
Date: Tue, 29 Oct 1996 16:57:20 -0800	[thread overview]
Message-ID: <199610300057.QAA19660@hermes.astro.washington.edu> (raw)

The following code demonstrates a bug in xdr_double() on an alpha pc164
running RedHat 4.0 Linux.

#include <stdio.h>

#include <rpc/types.h>
#include <rpc/xdr.h>

int
main()
{
	double d = 1.0;
	XDR xdrs;

	xdrstdio_create(&xdrs, stdout, XDR_ENCODE);

	xdr_double(&xdrs, &d);
	xdr_destroy(&xdrs);
	return 0;
}

When compiled with gcc version 2.7.2 and linked with libc-1.93, and
run with a command:
a.out > tst.out
tst.out contains, according to od -t x4 tst.out:
0000000 00000000 00000001

It SHOULD contain:
0000000 3ff00000 00000000

The version string in the library is the following:

GNU C Library alpha release version 1.93, by Roland McGrath et al.
Compiled by GNU CC version 2.7.2.
Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Report bugs to <bug-glibc@gnu.ai.mit.edu>.

Looking at sunrpc/xdr_float.c, it appears there are two problems:

1) The code assumes that sizeof(long) == sizeof(double)/2.  For the
alpha, sizeof(long) == sizeof(double).

2) Even if an int were used instead of a long, the second word of a
double needs to be written before the first word.  That is the
statement:
	return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
needs to read something like:
	return (XDR_PUTLONG(xdrs, lp+1) && XDR_PUTLONG(xdrs, lp++));
A similar change needs to be made to the DECODE statement:
                return (XDR_GETLONG(xdrs, lp++) && XDR_GETLONG(xdrs, lp));

-- 
Tom Quinn	Astronomy, University of Washington
Internet:	trq@astro.washington.edu
Phone:		206-685-9009

--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null

                 reply	other threads:[~1996-10-30  0:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox