aboutsummaryrefslogtreecommitdiff
path: root/engines/sky
diff options
context:
space:
mode:
authorD G Turner2014-04-22 03:42:45 +0100
committerD G Turner2014-04-22 03:42:45 +0100
commitd356f1716110ab374e394bf1fa80be0edf94b9b7 (patch)
treeda09efa55dc2cd6b41c9971549949302abaacbb3 /engines/sky
parenta48e54c4595329afabd3247a1a9ac560ae258f05 (diff)
downloadscummvm-rg350-d356f1716110ab374e394bf1fa80be0edf94b9b7.tar.gz
scummvm-rg350-d356f1716110ab374e394bf1fa80be0edf94b9b7.tar.bz2
scummvm-rg350-d356f1716110ab374e394bf1fa80be0edf94b9b7.zip
SKY: Improve parameter validation in debug console.
This fixes the issues reported in Feature Request #218 - "DEBUGGER: Add parameter validation".
Diffstat (limited to 'engines/sky')
-rw-r--r--engines/sky/debug.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/engines/sky/debug.cpp b/engines/sky/debug.cpp
index a417bc2ece..63da42eec2 100644
--- a/engines/sky/debug.cpp
+++ b/engines/sky/debug.cpp
@@ -1108,6 +1108,15 @@ void Debugger::postEnter() {
_mouse->resetCursor();
}
+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_ShowGrid(int argc, const char **argv) {
_showGrid = !_showGrid;
DebugPrintf("Show grid: %s\n", _showGrid ? "On" : "Off");
@@ -1299,22 +1308,20 @@ bool Debugger::Cmd_ScriptVar(int argc, const char **argv) {
}
bool Debugger::Cmd_Section(int argc, const char **argv) {
- if (argc < 2) {
- DebugPrintf("Example: %s 4\n", argv[0]);
- return true;
- }
-
- const int baseId[] = { START_ONE, START_S6, START_29, START_SC31, START_SC66, START_SC90, START_SC81 };
- int section = atoi(argv[1]);
+ if (argc == 2 && isNumeric(argv[1])) {
+ const int baseId[] = { START_ONE, START_S6, START_29, START_SC31, START_SC66, START_SC90, START_SC81 };
+ int section = atoi(argv[1]);
- if (section >= 0 && section <= 6) {
- _logic->fnEnterSection(section == 6 ? 4 : section, 0, 0);
- _logic->fnAssignBase(ID_FOSTER, baseId[section], 0);
- _skyCompact->fetchCpt(ID_FOSTER)->megaSet = 0;
+ if (section >= 0 && section <= 6) {
+ _logic->fnEnterSection(section == 6 ? 4 : section, 0, 0);
+ _logic->fnAssignBase(ID_FOSTER, baseId[section], 0);
+ _skyCompact->fetchCpt(ID_FOSTER)->megaSet = 0;
+ } else {
+ DebugPrintf("Section %d is out of range (range: %d - %d)\n", section, 0, 6);
+ }
} else {
- DebugPrintf("Unknown section '%s'\n", argv[1]);
+ DebugPrintf("Example: %s 4\n", argv[0]);
}
-
return true;
}