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]
To: macallan@xxxxxxxxxx
Subject: [Freeciv-Dev] (PR#13416) 64bit glitch
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Jul 2005 21:02:50 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [macallan@xxxxxxxxxx - Thu Jul 07 11:12:27 2005]:
> 
> 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:

Oh my.  This entire file is evil.

But this patch should fix that code.  Maybe.  I agree a uint64 would be
better here.  The patch is for 2.0 (maybe the asserts should be left
out) but should be applied to the dev branch as well, of course.

-jason

Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.15
diff -p -u -r1.15 dataio.c
--- common/dataio.c     16 Sep 2004 03:20:13 -0000      1.15
+++ common/dataio.c     8 Jul 2005 04:01:01 -0000
@@ -198,6 +198,7 @@ void dio_put_uint8(struct data_out *dout
   if (enough_space(dout, 1)) {
     unsigned char x = value;
 
+    assert(sizeof(x) == 1);
     memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 1);
     dout->current++;
   }
@@ -211,6 +212,7 @@ void dio_put_uint16(struct data_out *dou
   if (enough_space(dout, 2)) {
     unsigned short x = htons(value);
 
+    assert(sizeof(x) == 2);
     memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 2);
     dout->current += 2;
   }
@@ -222,8 +224,9 @@ void dio_put_uint16(struct data_out *dou
 void dio_put_uint32(struct data_out *dout, int value)
 {
   if (enough_space(dout, 4)) {
-    unsigned long x = htonl(value);
+    unsigned int x = htonl(value);
 
+    assert(sizeof(x) == 4);
     memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 4);
     dout->current += 4;
   }
@@ -405,6 +408,7 @@ void dio_get_uint8(struct data_in *din, 
     if (dest) {
       unsigned char x;
 
+      assert(sizeof(x) == 1);
       memcpy(&x, ADD_TO_POINTER(din->src, din->current), 1);
       *dest = x;
     }
@@ -421,6 +425,7 @@ void dio_get_uint16(struct data_in *din,
     if (dest) {
       unsigned short x;
 
+      assert(sizeof(x) == 2);
       memcpy(&x, ADD_TO_POINTER(din->src, din->current), 2);
       *dest = ntohs(x);
     }
@@ -435,8 +440,9 @@ void dio_get_uint32(struct data_in *din,
 {
   if (enough_data(din, 4)) {
     if (dest) {
-      unsigned long x;
+      unsigned int x;
 
+      assert(sizeof(x) == 4);
       memcpy(&x, ADD_TO_POINTER(din->src, din->current), 4);
       *dest = ntohl(x);
     }

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