Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[Freeciv-Dev] (PR#9031) uninitialized CM
Home

[Freeciv-Dev] (PR#9031) uninitialized CM

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9031) uninitialized CM
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 19 Jun 2004 13:06:09 -0700
Reply-to: rt@xxxxxxxxxxx

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

The CM cache3.results was previously static, and recently made into a 
malloced value.  Apparently it needs to be initialized as well, so that 
cache3.results[i].combinations[j].is_valid will be set to false and 
cache3.results[i].combinasions[j].cache1 will be set to NULL.

(Note this assumes that (int)NULL == (int)0, which isn't necessarily 
true but is on all platforms Freeciv is likely to be used on, and is 
assumed elsewhere to be true.  But it would probably be better to get 
rid of this assumption.)

==1643== Conditional jump or move depends on uninitialised value(s)
==1643==    at 0x813A4DD: build_cache3 (cm.c:1169)
==1643==    by 0x8139A34: optimize_final (cm.c:1331)
==1643==    by 0x81396C1: cm_query_result (cm.c:1477)
==1643==    by 0x806B672: auto_arrange_workers (cityturn.c:196)
==1643==    by 0x8067A9D: create_city (citytools.c:1117)
==1643==    by 0x80642B5: unit_enter_hut (unittools.c:2385)
==1643==    by 0x80616B4: move_unit (unittools.c:2833)
==1643==    by 0x80ADCF9: handle_unit_move_request (unithand.c:1173)
==1643==    by 0x80AF318: handle_unit_move (unithand.c:590)
==1643==    by 0x812C316: ai_unit_move (aitools.c:850)
==1643==    by 0x80763AE: do_unit_goto (gotohand.c:1361)
==1643==    by 0x812B972: ai_unit_goto (aitools.c:582)
==1643==    by 0x812D40E: ai_manage_explorer (aiunit.c:589)
==1643==    by 0x812D44D: ai_manage_explorer (aiunit.c:598)
==1643==    by 0x812D44D: ai_manage_explorer (aiunit.c:598)
==1643==    by 0x812FC68: ai_manage_unit (aiunit.c:2813)
==1643==    by 0x8130025: ai_manage_units (aiunit.c:2829)
==1643==    by 0x80511A9: begin_phase (srv_main.c:433)
==1643==    by 0x80503E0: main_loop (srv_main.c:1374)
==1643==    by 0x804F219: srv_main (srv_main.c:1521)
==1643==    by 0x804A3CC: main (civserver.c:161)
 > ==1643==
==1643== Conditional jump or move depends on uninitialised value(s)
==1643==    at 0x8139724: cm_clear_cache (cm.c:582)
==1643==    by 0x806B5D8: auto_arrange_workers (cityturn.c:165)
==1643==    by 0x8125957: ai_manage_cities (aicity.c:574)
==1643==    by 0x8128A53: ai_do_last_activities (aihand.c:319)
==1643==    by 0x8050937: end_turn (srv_main.c:519)
==1643==    by 0x805051E: main_loop (srv_main.c:1433)
==1643==    by 0x804F219: srv_main (srv_main.c:1521)
==1643==    by 0x804A3CC: main (civserver.c:161)

jason

? gmon.out
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.26
diff -u -r1.26 cm.c
--- common/aicore/cm.c  16 Jun 2004 03:01:02 -0000      1.26
+++ common/aicore/cm.c  19 Jun 2004 20:02:00 -0000
@@ -1438,9 +1438,12 @@
 ****************************************************************************/
 void cm_init_citymap(void)
 {
-  cache3.results
-    = fc_realloc(cache3.results,
-                (MAX_FIELDS_USED + 1) * sizeof(*cache3.results));
+  size_t size = (MAX_FIELDS_USED + 1) * sizeof(*cache3.results);
+
+  cache3.results = fc_realloc(cache3.results, size);
+
+  /* Initialize all values to NULL/0/FALSE */
+  memset(cache3.results, 0, size);
 }
 
 /****************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9031) uninitialized CM, Jason Short <=