tests: Fix crash when getstarg() fails
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 9 Jan 2015 15:19:13 +0000 (16:19 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Mar 2015 07:20:48 +0000 (08:20 +0100)
Screwed up when test-suite-only command __cmd was added in commit
e852d45.  Should never happen with the intended use.  Fix it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/testing.c

index 8ce5616a39528ae2714ce31a58201c858c3ca573..7fdfdd153831364b57b633a7f5f2ae1bbfc513a3 100644 (file)
@@ -27,7 +27,7 @@
  *  testing.c: Commands for test-suite use
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2014
+ *     Markus Armbruster, 2014-2015
  */
 
 #include <config.h>
@@ -46,10 +46,16 @@ testing_cmd(void)
        return RET_SYN;
     if (!strcmp(p, "added")) {
        p = getstarg(player->argp[2], "number? ", buf);
+       if (!p || !*p)
+           return RET_SYN;
        test_suite_prng_seed -= strtol(p, NULL, 10);
        p = getstarg(player->argp[3], "BTUs? ", buf);
+       if (!p || !*p)
+           return RET_SYN;
        player->btused -= strtol(p, NULL, 10);
        p = getstarg(player->argp[4], "money? ", buf);
+       if (!p)
+           return RET_SYN;
        player->dolcost -= strtod(p, NULL);
        return RET_OK;
     }