Summary: Trouble saving/loading players' known territory for
player indices >=40
                 Project: Freeciv
            Submitted by: jtn
            Submitted on: Sat Nov 19 17:26:25 2011
                Category: general
                Severity: 5 - Blocker
                Priority: 5 - Normal
                  Status: None
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
                 Release: 2.3.1
         Discussion Lock: Any
        Operating System: Any
         Planned Release: 2.3.2,2.4.0,2.5.0



Split out from bug #18776 / bug #19007. This is the /8 *32 confusion
discussed in 18776 comment 21 <http://gna.org/bugs/index.php?18776#comment21>
and later.

In savegame2.c:sg_save_map_known():

  int *known = fc_calloc(lines * MAP_INDEX_SIZE, sizeof(*known));

  /* HACK: we convert the data into a 32-bit integer, and then save it as
   * hex. */

  whole_map_iterate(ptile) {
    players_iterate(pplayer) {
      if (map_is_known(ptile, pplayer)) {
        p = player_index(pplayer);
        l = p / 32;
        known[l * MAP_INDEX_SIZE + tile_index(ptile)]
          |= (1u << (p - l * 8));
    } players_iterate_end;
  } whole_map_iterate_end;

The "p - l * 8" should be "p - l * 32". There's a symmetric error in

I think the consequence is that known information is not saved/loaded for
players with indices 40 and above; instead, zeroes are saved/loaded. (The
arithmetic starts going wrong at index 32, but indices 32..39 are saved/loaded
by luck, in the wrong bit positions; after that all the data is shifted off
the left end.)

This affects any game with >40 players (including barbarians) regardless of
whether /remove is used. It can also affect games with fewer players if
/remove is used (in-game or pre-game).

There are some patches attached to bug #18776 which partially address this,
e.g. file #14574, but they don't deal with backwards compatibility with old
savefiles. This will be tricky.


Reply to this item at:


  Message sent via/by Gna!

Freeciv-dev mailing list

Reply via email to