]> git.pond.sub.org Git - empserver/commit
Avoid false positive generation oops in navigate and march
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Jul 2011 07:53:39 +0000 (09:53 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 9 Jul 2011 13:16:21 +0000 (15:16 +0200)
commit3de1e8be28915337b4908dc3a3500014b7d88f0b
tree451853da0c62159bf55b57396bd64727ce4178f5
parent36015e8c0e075b698eb69ea07d34bd6fe27da55e
Avoid false positive generation oops in navigate and march

Commit e3cf1e32 (v4.3.27) created make_stale_if_command_arg() to
permit catching more potential yields on input.  Unfortunately, the
implementation of navigate and march sub-commands 'r', 'l' and 's'
breaks it.

do_unit_move() reads units into a unit list at the beginning and at
each stop.  It writes them back when they move or sweep.  If a unit
changed in the file in between, the changes would get wiped out.
Therefore, do_unit_move() must not yield between stops.

do_unit_move() parses sub-commands into player->argp[], then supplies
defaults for missing arguments, so that code using them (radar(),
do_look(), sona(), mine(), landmine()) won't prompt for missing
arguments.  Unclean and brittle.  See also commit 28cc236e and commit
45106ab9.

Unfortunately, make_stale_if_command_arg() doesn't recognize the
difference between these defaulted arguments and parsed arguments, so
it makes objects stale, even though the defaulted arguments can't be
missing.  If a move or sweep follows, it triggers a false positive
generation oops.

To fix, test "points into argument buffer" (only true for parsed
arguments) instead of "is in player->argp[]".  Requires making the
argument buffer accessible: new struct player member argbuf[].  Use it
for parsing commands, in command(), execute(), do_unit_move().  Don't
use it in emp_config(), player_login(), move_ground(), because these
parse something else.
include/player.h
src/lib/commands/navi.c
src/lib/player/player.c