From 1f950f6a7099cdef9293e79153f39a278eac643a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 27 Jan 2013 15:43:39 +0100 Subject: [PATCH] edit: Report unit key 'U' failure more nicely, and avoid oops Two failure modes: * When the argument is negative, edit() attempts an invalid write, triggering an oops. edit() detects the write failure, and returns RET_FAIL. Detect the negative argument instead, and return RET_SYN, like we do for other invalid edit arguments. * When the argument requires the table to be extended, but the extension fails, edit() returns RET_FAIL. Additionally report the failure to the player. Signed-off-by: Markus Armbruster --- src/lib/commands/edit.c | 12 ++++++------ tests/actofgod/journal.log | 6 +++--- tests/actofgod/server.log | 3 --- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 28877ad7..7f5ed1a1 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -193,8 +193,6 @@ edit(void) return RET_FAIL; if ((err = edit_ship(&ship, key, ptr)) != RET_OK) return err; - if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50)) - return RET_FAIL; if (!putship(ship.shp_uid, &ship)) return RET_FAIL; break; @@ -203,8 +201,6 @@ edit(void) return RET_FAIL; if ((err = edit_land(&land, key, ptr)) != RET_OK) return err; - if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50)) - return RET_FAIL; if (!putland(land.lnd_uid, &land)) return RET_FAIL; break; @@ -213,8 +209,6 @@ edit(void) return RET_FAIL; if ((err = edit_plane(&plane, key, ptr)) != RET_OK) return err; - if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50)) - return RET_FAIL; if (!putplane(plane.pln_uid, &plane)) return RET_FAIL; break; @@ -749,6 +743,12 @@ edit_unit(struct empobj *unit, char *key, char *p, switch (toupper(*key)) { case 'U': + if (arg < 0) + return RET_SYN; + if (!ef_ensure_space(unit->ef_type, arg, 50)) { + pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg); + return RET_FAIL; + } ef_set_uid(unit->ef_type, unit, arg); break; case 'O': diff --git a/tests/actofgod/journal.log b/tests/actofgod/journal.log index e8885794..c80a004b 100644 --- a/tests/actofgod/journal.log +++ b/tests/actofgod/journal.log @@ -858,7 +858,7 @@ Play#0 output Play#0 6 0 640 Play#0 input edit s 0 U 0 U -1 Play#0 command edit - Play#0 output Play#0 1 command failed + Play#0 output Play#0 1 Usage: edit [ ]... Play#0 output Play#0 6 0 640 Play#0 input edit s 2 L 3,-1 Play#0 command edit @@ -896,7 +896,7 @@ Play#0 output Play#0 6 0 640 Play#0 input edit p 0 U 0 U -1 Play#0 command edit - Play#0 output Play#0 1 command failed + Play#0 output Play#0 1 Usage: edit [ ]... Play#0 output Play#0 6 0 640 Play#0 input edit p 2 l 3,-1 Play#0 command edit @@ -934,7 +934,7 @@ Play#0 output Play#0 6 0 640 Play#0 input edit u 0 U 0 U -1 Play#0 command edit - Play#0 output Play#0 1 command failed + Play#0 output Play#0 1 Usage: edit [ ]... Play#0 output Play#0 6 0 640 Play#0 input edit u 2 L 3,-1 Play#0 command edit diff --git a/tests/actofgod/server.log b/tests/actofgod/server.log index 299fdaaa..15cbfe36 100644 --- a/tests/actofgod/server.log +++ b/tests/actofgod/server.log @@ -7,9 +7,6 @@ Connect from 127.0.0.1 Connect from 127.0.0.1 tester@127.0.0.1 using country #0 tester@127.0.0.1 logged in as country #0 -Oops: id < 0 in ../src/lib/common/file.c:973 -Oops: id < 0 in ../src/lib/common/file.c:973 -Oops: id < 0 in ../src/lib/common/file.c:973 tester@127.0.0.1 logged out, country #0 Shutdown commencing (cleaning up threads.) Server shutting down on signal 15