Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] (PR#10641) crash in mapgen
Home

[Freeciv-Dev] (PR#10641) crash in mapgen

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: use_less@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#10641) crash in mapgen
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Oct 2004 08:44:16 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10641 >

> [use_less - Wed Oct 20 10:22:26 2004]:
> 
> I start up the server, enter these commands:
> 
> set mapseed 1
> create Idiot
> start
> 
> and boom, crash.
> 
> The problem is in generator/utilities.c, line 111, where it sets minval
> and maxval.  On my win32 build, it sets both to -2147483648, probably
> due to an overflow in using the positive version of HUGE_VAL.
> 
> Here's a patch.

I'd rather just rewrite this to not use HUGE_VAL.

jason

? diff
? newtiles
Index: server/generator/utilities.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/generator/utilities.c,v
retrieving revision 1.11
diff -u -r1.11 utilities.c
--- server/generator/utilities.c        16 Oct 2004 22:29:13 -0000      1.11
+++ server/generator/utilities.c        20 Oct 2004 15:43:26 -0000
@@ -107,12 +107,19 @@
                             bool (*filter)(const struct tile *ptile,
                                            const void *data))
 {
-  int minval = +(int)HUGE_VAL, maxval = -(int)HUGE_VAL, total = 0;
+  int minval = 0, maxval = 0, total = 0;
+  bool first = TRUE;
 
   /* Determine minimum and maximum value. */
   whole_map_iterate_filtered(ptile, data, filter) {
-    maxval = MAX(maxval, int_map[ptile->index]);
-    minval = MIN(minval, int_map[ptile->index]);
+    if (first) {
+      minval = int_map[ptile->index];
+      maxval = int_map[ptile->index];
+    } else {
+      maxval = MAX(maxval, int_map[ptile->index]);
+      minval = MIN(minval, int_map[ptile->index]);
+    }
+    first = FALSE;
     total++;
   } whole_map_iterate_filtered_end;
 

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