<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40180 >
On 02/04/2008, Pepeto _ wrote:
>
> There are many #if 0 ... #endif added at revisions 13911 to 13913 in
> create_city_virtual() in common/city.c. Now, there are lot of
> uninitialized data in the structure, including notably the trade routes.
> The effects are random. Maybe some could explain me how it works well to
> don't initialize them or if this is effectively a bug.
Memory for city structure is allocated with fc_calloc(). It takes
care of zero initializations.
Comments should explain that. Patch attached.
- ML
diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c 2008-03-12 21:57:04.000000000 +0200
+++ freeciv/common/city.c 2008-04-03 02:59:38.000000000 +0300
@@ -2433,6 +2433,9 @@
struct tile *ptile, const char *name)
{
int i;
+
+ /* Make sure that contents of city structure are correctly
+ * initialized, if you ever allocate it by some other mean than fc_calloc() */
struct city *pcity = fc_calloc(1, sizeof(*pcity));
assert(pplayer != NULL); /* No unowned cities! */
@@ -2444,6 +2447,8 @@
assert(name != NULL);
sz_strlcpy(pcity->name, name);
+ /* City structure was allocated with fc_calloc(), so
+ * contents are initially zero. No need to initialize second time. */
#ifdef ZERO_VARIABLES_FOR_SEARCHING
/* This does not register the city, so the identity defaults to 0. */
pcity->id = IDENTITY_NUMBER_ZERO;
@@ -2486,7 +2491,8 @@
pcity->airlift = FALSE;
pcity->debug = FALSE;
#endif
- pcity->did_buy = TRUE; /* why? */
+ pcity->did_buy = TRUE; /* You cannot buy production same turn city is
+ * founded. */
#ifdef ZERO_VARIABLES_FOR_SEARCHING
pcity->did_sell = FALSE;
pcity->is_updated = FALSE;
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev