Follow-up Comment #10, bug #13814 (project freeciv):

The problem is around line 580 of ai/advmilitary.c, in assess_danger():

      if (unit_has_type_flag(punit, F_NUCLEAR)) {
        defender = ai_find_source_building(pcity, EFT_NUKE_PROOF,
                                           unit_class(punit),
MOVETYPE_LAST);
        danger_reduced[defender] += vulnerability * move_rate / MAX(dist,
1);
      } else if (!unit_has_type_flag(punit, F_IGWALL)) {
        defender = ai_find_source_building(pcity, EFT_DEFEND_BONUS,
                                           unit_class(punit),
MOVETYPE_LAST);
        danger_reduced[defender] += vulnerability * move_rate / MAX(dist,
1);
      } else {
        igwall_threat += vulnerability;
      }


ai_find_source_building() is returning 200, which equals B_LAST and is
out-of-bounds for the danger_reduced array.

In assess_danger_player(), myiter is stored only in %ebx instead of having a
memory location (gdb will tell you this if you do "print &myiter"). When this
function calls assess_danger(), %ebx (myiter) is saved on the stack in a
location that just happens to be immediately past the end of the
danger_reduced array. When vulnerability != 0, it gets stomped on.

Declare a few ints with unusual values at the very beginning of
assess_danger() and take their addresses so they're forced to exist on the
stack (instead of being register-only or optimized out), then have the
printf()'s display these values.

    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?13814>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to