[Freeciv-Dev] (PR#40180) Uninitialized datas in city structure
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40180 [EMAIL PROTECTED] - Jeu. Avr. 03 00:09:30 2008]: Memory for city structure is allocated with fc_calloc(). It takes care of zero initializations. Ok, thank you. I didn't know about it. Is it also the normal behaviour of standard lib C calloc()? ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40180) Uninitialized datas in city structure
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40180 On 03/04/2008, Pepeto _ wrote: [EMAIL PROTECTED] - Jeu. Avr. 03 00:09:30 2008]: Memory for city structure is allocated with fc_calloc(). It takes care of zero initializations. Ok, thank you. I didn't know about it. Is it also the normal behaviour of standard lib C calloc()? Yes, that's part of the standard. - ML ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40180) Uninitialized datas in city structure
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40180 Well, sorry for my ignorance spam. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40180) Uninitialized datas in city structure
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40180 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. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40180) Uninitialized datas in city structure
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.0 +0200 +++ freeciv/common/city.c 2008-04-03 02:59:38.0 +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 Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev