[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]
<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
|
|