[Scummvm-cvs-logs] SF.net SVN: scummvm:[42871] tools/branches/gsoc2009-gui

Remere at users.sourceforge.net Remere at users.sourceforge.net
Wed Jul 29 02:04:47 CEST 2009


Revision: 42871
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42871&view=rev
Author:   Remere
Date:     2009-07-29 00:04:45 +0000 (Wed, 29 Jul 2009)

Log Message:
-----------
*Fixed tools reading beyond end of arguments if you used invalid syntax.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/compress.cpp
    tools/branches/gsoc2009-gui/tools_cli.cpp

Modified: tools/branches/gsoc2009-gui/compress.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress.cpp	2009-07-28 23:19:33 UTC (rev 42870)
+++ tools/branches/gsoc2009-gui/compress.cpp	2009-07-29 00:04:45 UTC (rev 42871)
@@ -683,6 +683,8 @@
 			encparms.abr = 1;
 		} else if (arg == "-b") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -b");
 			encparms.minBitr = atoi(_arguments[_arguments_parsed].c_str());
 
 			if ((encparms.minBitr % 8) != 0) {
@@ -699,6 +701,8 @@
 
 		} else if (arg == "-B") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -B");
 			encparms.maxBitr = atoi(_arguments[_arguments_parsed].c_str());
 
 			if ((encparms.maxBitr % 8) != 0) {
@@ -715,6 +719,8 @@
 
 		} else if (arg == "-V") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -V");
 			encparms.vbrqual = atoi(_arguments[_arguments_parsed].c_str());
 
 			if (encparms.vbrqual < 0) {
@@ -727,6 +733,8 @@
 
 		} else if (arg == "-q") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -q");
 			encparms.algqual = atoi(_arguments[_arguments_parsed].c_str());
 
 			if (encparms.algqual < 0) {
@@ -755,6 +763,8 @@
 
 		if (arg == "-b") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -b");
 			oggparms.nominalBitr = atoi(_arguments[_arguments_parsed].c_str());
 
 			if ((oggparms.nominalBitr % 8) != 0) {
@@ -771,6 +781,8 @@
 
 		} else if (arg == "-m") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -m");
 			oggparms.minBitr = atoi(_arguments[_arguments_parsed].c_str());
 
 			if ((oggparms.minBitr % 8) != 0) {
@@ -787,6 +799,8 @@
 
 		} else if (arg == "-M") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -M");
 			oggparms.maxBitr = atoi(_arguments[_arguments_parsed].c_str());
 
 			if ((oggparms.maxBitr % 8) != 0) {
@@ -822,6 +836,8 @@
 
 		if (arg == "-b") {
 			++_arguments_parsed;
+			if (_arguments_parsed >= _arguments.size())
+				throw ToolException("Could not parse command line options, expected value after -b");
 			flacparms.blocksize = atoi(_arguments[_arguments_parsed].c_str());
 		} else if (arg == "--fast") {
 			flacparms.compressionLevel = 0;
@@ -852,6 +868,8 @@
 		} else {
 			break;
 		}
+
+		++_arguments_parsed;
 	}
 
 	return true;

Modified: tools/branches/gsoc2009-gui/tools_cli.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tools_cli.cpp	2009-07-28 23:19:33 UTC (rev 42870)
+++ tools/branches/gsoc2009-gui/tools_cli.cpp	2009-07-29 00:04:45 UTC (rev 42871)
@@ -45,6 +45,9 @@
 
 	ToolType type = TOOLTYPE_ALL;
 
+	if (arguments.empty())
+		std::cout << "\tExpected more arguments\n";
+
 	// Check first argument
 	std::string option = arguments.front();
 	if (option == "--tool" || option == "-t") {
@@ -86,11 +89,20 @@
 			arguments.pop_front();
 		}
 
+		// Only possible if compress/extract was parsed
+		if (arguments.empty())
+			std::cout << "\tExpected more arguments after '" << option << "'\n";
+
 		// Find out what tools take this file as input
-		ToolList choices = inspectInput(type, arguments);
+		ToolList choices = inspectInput(type, arguments.front());
 		Tool *tool = NULL;
 
-		if (choices.size() > 1) {
+		if (choices.empty()) {
+			std::cout << "\tNo tool could parse input file '" << arguments.front() << "', use --list to list all available tools and --tool to force running the correct one.\n";
+			std::cout << "\tIf you intended to specify tool-specific options, do so AFTER the input file.\n\n";
+			std::cout << "\tExample: tools_cli monster.sou --vorbis\n";
+			return 0;
+		} else if (choices.size() > 1) {
 			std::cout << "\tMultiple tools accept this input:\n\n";
 
 			// Present a list of possible tools
@@ -140,8 +152,9 @@
 		"\tScumm VM Tools master interface\n" <<
 		"\n" <<
 		"\tCommon use:\n" <<
-		"\ttools [--tool <tool name>] [compression options] [-o output directory] <input args>\n" <<
-		"\ttools [extract|compress] <input args>\n" <<
+		"\ttools [--tool <tool name>] [compression options] [-o output directory] [tool args] <input args>\n" <<
+		"\ttools [extract|compress] <input args> [tool args]\n" <<
+		"\tNote that on the second form, tool arguments are specified AFTER the input file.\n" <<
 		"\n" <<
 		"\tOther Options:\n" <<
 		"\t--help\tDisplay this text\n" <<


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list