[Scummvm-cvs-logs] scummvm master -> d356f1716110ab374e394bf1fa80be0edf94b9b7

digitall dgturner at iee.org
Tue Apr 22 04:38:54 CEST 2014


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a48e54c459 QUEEN: Improve parameter validation in debug console.
d356f17161 SKY: Improve parameter validation in debug console.


Commit: a48e54c4595329afabd3247a1a9ac560ae258f05
    https://github.com/scummvm/scummvm/commit/a48e54c4595329afabd3247a1a9ac560ae258f05
Author: D G Turner (digitall at scummvm.org)
Date: 2014-04-22T03:40:51+01:00

Commit Message:
QUEEN: Improve parameter validation in debug console.

This fixes the issues reported in Feature Request #218 - "DEBUGGER:
Add parameter validation".

Changed paths:
    engines/queen/debug.cpp



diff --git a/engines/queen/debug.cpp b/engines/queen/debug.cpp
index 96fa814..3706806 100644
--- a/engines/queen/debug.cpp
+++ b/engines/queen/debug.cpp
@@ -21,6 +21,7 @@
  */
 
 #include "common/scummsys.h"
+#include "common/util.h"
 
 #include "queen/debug.h"
 
@@ -57,8 +58,17 @@ void Debugger::postEnter() {
 	_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) {
-	if (argc == 2) {
+	if (argc == 2 && isNumeric(argv[1])) {
 		uint16 sm = atoi(argv[1]);
 		_vm->logic()->executeSpecialMove(sm);
 		return false;
@@ -75,12 +85,17 @@ bool Debugger::Cmd_Areas(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]);
 		if (bobNum >= Graphics::MAX_BOBS_NUMBER) {
 			DebugPrintf("Bob %d is out of range (range: 0 - %d)\n", bobNum, Graphics::MAX_BOBS_NUMBER);
 		} 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);
 			if (!strcmp(argv[2], "toggle")) {
 				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) {
 	uint16 slot;
-	switch (argc) {
-	case 2:
-		slot = atoi(argv[1]);
-		DebugPrintf("GAMESTATE[%d] ", slot);
-		DebugPrintf("is %d\n", _vm->logic()->gameState(slot));
-		break;
-	case 3:
+	if ((argc == 2 || argc == 3) && isNumeric(argv[1])) {
 		slot = atoi(argv[1]);
 		DebugPrintf("GAMESTATE[%d] ", slot);
-		DebugPrintf("was %d ", _vm->logic()->gameState(slot));
-		_vm->logic()->gameState(slot, atoi(argv[2]));
-		DebugPrintf("now %d\n", _vm->logic()->gameState(slot));
-		break;
-	default:
-		DebugPrintf("Usage: %s slotnum value\n", argv[0]);
-		break;
+		DebugPrintf("%s %d\n", (argc == 2) ? "is" : "was", _vm->logic()->gameState(slot));
+
+		if (argc == 3) {
+			if (isNumeric(argv[1])) {
+				_vm->logic()->gameState(slot, atoi(argv[2]));
+				DebugPrintf("now %d\n", _vm->logic()->gameState(slot));
+			} else {
+				DebugPrintf("Usage: %s slotnum <value>\n", argv[0]);
+			}
+		}
+	} else {
+		DebugPrintf("Usage: %s slotnum <value>\n", argv[0]);
 	}
 	return true;
 }
@@ -164,7 +178,7 @@ bool Debugger::Cmd_PrintBobs(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]);
 		_vm->logic()->joePos(0, 0);
 		_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) {
-	if (argc == 2) {
+	if (argc == 2 && isNumeric(argv[1])) {
 		int16 songNum = atoi(argv[1]);
 		_vm->sound()->playSong(songNum);
 		DebugPrintf("Playing song %d\n", songNum);


Commit: d356f1716110ab374e394bf1fa80be0edf94b9b7
    https://github.com/scummvm/scummvm/commit/d356f1716110ab374e394bf1fa80be0edf94b9b7
Author: D G Turner (digitall at scummvm.org)
Date: 2014-04-22T03:42:45+01:00

Commit Message:
SKY: Improve parameter validation in debug console.

This fixes the issues reported in Feature Request #218 - "DEBUGGER:
Add parameter validation".

Changed paths:
    engines/sky/debug.cpp



diff --git a/engines/sky/debug.cpp b/engines/sky/debug.cpp
index a417bc2..63da42e 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;
 }
 






More information about the Scummvm-git-logs mailing list