QUEEN: Improve parameter validation in debug console.

This fixes the issues reported in Feature Request #218 - "DEBUGGER:
Add parameter validation".
This commit is contained in:
D G Turner 2014-04-22 03:40:51 +01:00
parent 9a9bc35a93
commit a48e54c459

View file

@ -21,6 +21,7 @@
*/ */
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/util.h"
#include "queen/debug.h" #include "queen/debug.h"
@ -57,8 +58,17 @@ void Debugger::postEnter() {
_vm->graphics()->setupMouseCursor(); _vm->graphics()->setupMouseCursor();
} }
static bool isNumeric(const char *arg) {
const char *str = arg;
bool retVal = true;
while (retVal && (*str != '\0')) {
retVal = Common::isDigit(*str++);
}
return retVal;
}
bool Debugger::Cmd_Asm(int argc, const char **argv) { bool Debugger::Cmd_Asm(int argc, const char **argv) {
if (argc == 2) { if (argc == 2 && isNumeric(argv[1])) {
uint16 sm = atoi(argv[1]); uint16 sm = atoi(argv[1]);
_vm->logic()->executeSpecialMove(sm); _vm->logic()->executeSpecialMove(sm);
return false; return false;
@ -75,12 +85,17 @@ bool Debugger::Cmd_Areas(int argc, const char **argv) {
} }
bool Debugger::Cmd_Bob(int argc, const char **argv) { bool Debugger::Cmd_Bob(int argc, const char **argv) {
if (argc >= 3) { if (argc >= 3 && isNumeric(argv[1])) {
int bobNum = atoi(argv[1]); int bobNum = atoi(argv[1]);
if (bobNum >= Graphics::MAX_BOBS_NUMBER) { if (bobNum >= Graphics::MAX_BOBS_NUMBER) {
DebugPrintf("Bob %d is out of range (range: 0 - %d)\n", bobNum, Graphics::MAX_BOBS_NUMBER); DebugPrintf("Bob %d is out of range (range: 0 - %d)\n", bobNum, Graphics::MAX_BOBS_NUMBER);
} else { } else {
int param = (argc > 3) ? atoi(argv[3]) : 0; int param = 0;
if (argc > 3 && isNumeric(argv[3])) {
param = atoi(argv[3]);
} else {
DebugPrintf("Invalid parameter for bob command '%s'\n", argv[2]);
}
BobSlot *bob = _vm->graphics()->bob(bobNum); BobSlot *bob = _vm->graphics()->bob(bobNum);
if (!strcmp(argv[2], "toggle")) { if (!strcmp(argv[2], "toggle")) {
bob->active = !bob->active; bob->active = !bob->active;
@ -109,22 +124,21 @@ bool Debugger::Cmd_Bob(int argc, const char **argv) {
bool Debugger::Cmd_GameState(int argc, const char **argv) { bool Debugger::Cmd_GameState(int argc, const char **argv) {
uint16 slot; uint16 slot;
switch (argc) { if ((argc == 2 || argc == 3) && isNumeric(argv[1])) {
case 2:
slot = atoi(argv[1]); slot = atoi(argv[1]);
DebugPrintf("GAMESTATE[%d] ", slot); DebugPrintf("GAMESTATE[%d] ", slot);
DebugPrintf("is %d\n", _vm->logic()->gameState(slot)); DebugPrintf("%s %d\n", (argc == 2) ? "is" : "was", _vm->logic()->gameState(slot));
break;
case 3: if (argc == 3) {
slot = atoi(argv[1]); if (isNumeric(argv[1])) {
DebugPrintf("GAMESTATE[%d] ", slot); _vm->logic()->gameState(slot, atoi(argv[2]));
DebugPrintf("was %d ", _vm->logic()->gameState(slot)); DebugPrintf("now %d\n", _vm->logic()->gameState(slot));
_vm->logic()->gameState(slot, atoi(argv[2])); } else {
DebugPrintf("now %d\n", _vm->logic()->gameState(slot)); DebugPrintf("Usage: %s slotnum <value>\n", argv[0]);
break; }
default: }
DebugPrintf("Usage: %s slotnum value\n", argv[0]); } else {
break; DebugPrintf("Usage: %s slotnum <value>\n", argv[0]);
} }
return true; return true;
} }
@ -164,7 +178,7 @@ bool Debugger::Cmd_PrintBobs(int argc, const char**argv) {
} }
bool Debugger::Cmd_Room(int argc, const char **argv) { bool Debugger::Cmd_Room(int argc, const char **argv) {
if (argc == 2) { if (argc == 2 && isNumeric(argv[1])) {
uint16 roomNum = atoi(argv[1]); uint16 roomNum = atoi(argv[1]);
_vm->logic()->joePos(0, 0); _vm->logic()->joePos(0, 0);
_vm->logic()->newRoom(roomNum); _vm->logic()->newRoom(roomNum);
@ -180,7 +194,7 @@ bool Debugger::Cmd_Room(int argc, const char **argv) {
} }
bool Debugger::Cmd_Song(int argc, const char **argv) { bool Debugger::Cmd_Song(int argc, const char **argv) {
if (argc == 2) { if (argc == 2 && isNumeric(argv[1])) {
int16 songNum = atoi(argv[1]); int16 songNum = atoi(argv[1]);
_vm->sound()->playSong(songNum); _vm->sound()->playSong(songNum);
DebugPrintf("Playing song %d\n", songNum); DebugPrintf("Playing song %d\n", songNum);