Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13416) 64bit glitch
Home

[Freeciv-Dev] (PR#13416) 64bit glitch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13416) 64bit glitch
From: "Michael Lorenz" <macallan@xxxxxxxxxx>
Date: Thu, 7 Jul 2005 04:12:28 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13416 >

Hello,

even 2.0.2 contains the following bug which prevents freeciv from
working on big-endian 64bit platforms like NetBSD/sparc64. In
common/dataio.c:

line 222
void dio_put_uint32(struct data_out *dout, int value)
{
  if (enough_space(dout, 4)) {
    unsigned long x = htonl(value);

    memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 4);
    dout->current += 4;
  }
}

x needs to be an unsigned int or better an uint32_t  because longs are
64bit on 64bit CPUs, copying only the upper 4 bytes doesn't do any good
here.

Same again here:
line 434
void dio_get_uint32(struct data_in *din, int *dest)
{
  if (enough_data(din, 4)) {
    if (dest) {
      unsigned long x;

      memcpy(&x, ADD_TO_POINTER(din->src, din->current), 4);
      *dest = ntohl(x);
    }
    din->current += 4;
  }
}
... which copies random data to *dest.
Besides that it works fine.

have fun
Michael

Attachment: pgp6ZrGqaETZ9.pgp
Description: PGP signature


[Prev in Thread] Current Thread [Next in Thread]