Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[Freeciv-Dev] Re: (PR#8975) cm clear_cache() called before build_cache3(
Home

[Freeciv-Dev] Re: (PR#8975) cm clear_cache() called before build_cache3(

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: use_less@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#8975) cm clear_cache() called before build_cache3()
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 13 Jun 2004 20:51:38 -0700
Reply-to: rt@xxxxxxxxxxx

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

James Canete wrote:

> The way I got a crash was with MAX_FIELDS_USED #define'd to
> (CITY_TILES), which means that even if CITY_TILES is set to zero, it
> goes through this loop once:
>   for (i = 0; i < MAX_FIELDS_USED + 1; i++) {
> 
> I'm thinking all the "+ 1"s used with MAX_FIELDS_USED should probably be
> removed if MAX_FIELDS_USED were set equal to CITY_TILES, then.

Well this is ugly.  It assumes that if MAX_FIELDS_USED is 0 then there 
is at least 1 item in the list.  That is, 0 means the set of {0}, with 1 
element in it.

One possibility is to have a special case:

   #define MAX_FIELDS_USED (city_tiles > 0 ? city_tiles : -1)

but this is extremely ugly.

Another possibility is to make sure the realloc call is done in all 
cases.  So even if the topology is undefined and city_tiles is 0, we 
will have 1 entry in the results array.

Yet another possibility is to treat the "undefined" case separate from 
the 0 case.  If the topology is undefined then city_tiles should be 
undefined (maybe -1?) instead of 0.

Like I said...ugly.

jason




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