[Scummvm-cvs-logs] SF.net SVN: scummvm:[33793] scummvm/trunk/engines/cine

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Tue Aug 12 02:13:29 CEST 2008


Revision: 33793
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33793&view=rev
Author:   buddha_
Date:     2008-08-12 00:13:27 +0000 (Tue, 12 Aug 2008)

Log Message:
-----------
Changed commandBuffer from a char[80] to Common::String and made FWRenderer::setCommand use a Common::String. Hopefully this might help with the command buffer overflow stuff, although this isn't a fix for the problem behind it, just a bandaid.

Modified Paths:
--------------
    scummvm/trunk/engines/cine/gfx.cpp
    scummvm/trunk/engines/cine/gfx.h
    scummvm/trunk/engines/cine/main_loop.cpp
    scummvm/trunk/engines/cine/various.cpp
    scummvm/trunk/engines/cine/various.h

Modified: scummvm/trunk/engines/cine/gfx.cpp
===================================================================
--- scummvm/trunk/engines/cine/gfx.cpp	2008-08-11 23:20:10 UTC (rev 33792)
+++ scummvm/trunk/engines/cine/gfx.cpp	2008-08-12 00:13:27 UTC (rev 33793)
@@ -530,7 +530,7 @@
 /*! \brief Set player command string
  * \param cmd New command string
  */
-void FWRenderer::setCommand(const char *cmd) {
+void FWRenderer::setCommand(Common::String cmd) {
 	_cmd = cmd;
 }
 

Modified: scummvm/trunk/engines/cine/gfx.h
===================================================================
--- scummvm/trunk/engines/cine/gfx.h	2008-08-11 23:20:10 UTC (rev 33792)
+++ scummvm/trunk/engines/cine/gfx.h	2008-08-12 00:13:27 UTC (rev 33793)
@@ -94,7 +94,7 @@
 
 	void drawFrame();
 	void blit();
-	void setCommand(const char *cmd);
+	void setCommand(Common::String cmd);
 
 	virtual void incrustMask(const objectStruct &obj, uint8 color = 0);
 	virtual void incrustSprite(const objectStruct &obj);

Modified: scummvm/trunk/engines/cine/main_loop.cpp
===================================================================
--- scummvm/trunk/engines/cine/main_loop.cpp	2008-08-11 23:20:10 UTC (rev 33792)
+++ scummvm/trunk/engines/cine/main_loop.cpp	2008-08-12 00:13:27 UTC (rev 33793)
@@ -284,7 +284,7 @@
 		menuCommandLen = 0;
 
 		playerCommand = -1;
-		strcpy(commandBuffer, "");
+		commandBuffer = "";
 
 		globalVars[VAR_MOUSE_X_POS] = 0;
 		globalVars[VAR_MOUSE_Y_POS] = 0;

Modified: scummvm/trunk/engines/cine/various.cpp
===================================================================
--- scummvm/trunk/engines/cine/various.cpp	2008-08-11 23:20:10 UTC (rev 33792)
+++ scummvm/trunk/engines/cine/various.cpp	2008-08-12 00:13:27 UTC (rev 33793)
@@ -78,7 +78,7 @@
 
 int16 playerCommand;
 
-char commandBuffer[80];
+Common::String commandBuffer;
 char currentPrcName[20];
 char currentRelName[20];
 char currentObjectName[20];
@@ -318,6 +318,18 @@
 	}
 }
 
+/*! \brief Save the 80 bytes long command buffer padded to that length with zeroes. */
+void saveCommandBuffer(Common::OutSaveFile &out) {
+	// Let's make sure there's space for the trailing zero
+	// (That's why we subtract one from the maximum command buffer size here).
+	uint32 size = MIN<uint32>(commandBuffer.size(), kMaxCommandBufferSize - 1);
+	out.write(commandBuffer.c_str(), size);
+	// Write the rest as zeroes (Here we also write the string's trailing zero)
+	for (uint i = 0; i < kMaxCommandBufferSize - size; i++) {
+		out.writeByte(0);
+	}
+}
+
 void saveAnimDataTable(Common::OutSaveFile &out) {
 	out.writeUint16BE(NUM_MAX_ANIMDATA); // Entry count
 	out.writeUint16BE(0x1E); // Entry size
@@ -635,7 +647,7 @@
 	playerCommand = -1;
 	isDrawCommandEnabled = 0;
 
-	strcpy(commandBuffer, "");
+	commandBuffer = "";
 
 	globalVars[VAR_MOUSE_X_POS] = 0;
 	globalVars[VAR_MOUSE_Y_POS] = 0;
@@ -836,7 +848,10 @@
 	globalVars.load(in, NUM_MAX_VAR);
 	loadZoneData(in);
 	loadCommandVariables(in);
-	in.read(commandBuffer, 0x50);
+	char tempCommandBuffer[kMaxCommandBufferSize];
+	in.read(tempCommandBuffer, kMaxCommandBufferSize);
+	commandBuffer = tempCommandBuffer;
+	renderer->setCommand(commandBuffer);
 	loadZoneQuery(in);
 
 	// TODO: Use the loaded string (Current music name (String, 13 bytes)).
@@ -973,7 +988,9 @@
 	loadCommandVariables(in);
 
 	// At 0x22A9 (i.e. 0x22A1 + 4 * 2):
-	in.read(commandBuffer, 0x50);
+	char tempCommandBuffer[kMaxCommandBufferSize];
+	in.read(tempCommandBuffer, kMaxCommandBufferSize);
+	commandBuffer = tempCommandBuffer;
 	renderer->setCommand(commandBuffer);
 
 	// At 0x22F9 (i.e. 0x22A9 + 0x50):
@@ -1121,7 +1138,7 @@
 	globalVars.save(out, NUM_MAX_VAR);
 	saveZoneData(out);
 	saveCommandVariables(out);
-	out.write(commandBuffer, 0x50);
+	saveCommandBuffer(out);
 
 	out.writeUint16BE(renderer->_cmdY);
 	out.writeUint16BE(bgVar0);
@@ -1336,7 +1353,7 @@
 	globalVars.save(out, NUM_MAX_VAR);
 	saveZoneData(out);
 	saveCommandVariables(out);
-	out.write(commandBuffer, 0x50);
+	saveCommandBuffer(out);
 	saveZoneQuery(out);
 
 	// FIXME: Save a proper name here, saving an empty string currently.
@@ -1462,9 +1479,9 @@
 	commandVar2 = -10;
 
 	if (playerCommand != -1) {
-		strcpy(commandBuffer, defaultActionCommand[playerCommand]);
+		commandBuffer = defaultActionCommand[playerCommand];
 	} else {
-		strcpy(commandBuffer, "");
+		commandBuffer = "";
 	}
 
 	if ((playerCommand != -1) && (choiceResultTable[playerCommand] == 2)) {	// need object selection ?
@@ -1480,7 +1497,7 @@
 
 		if (si < 0) {
 			playerCommand = -1;
-			strcpy(commandBuffer, "");
+			commandBuffer = "";
 		} else {
 			if (g_cine->getGameType() == Cine::GType_OS) {
 				if (si >= 8000) {
@@ -1493,11 +1510,10 @@
 
 			commandVar3[0] = si;
 			commandVar1 = 1;
-
-			strcat(commandBuffer, " ");
-			strcat(commandBuffer, objectTable[commandVar3[0]].name);
-			strcat(commandBuffer, " ");
-			strcat(commandBuffer, commandPrepositionOn);
+			commandBuffer += " ";
+			commandBuffer += objectTable[commandVar3[0]].name;
+			commandBuffer += " ";
+			commandBuffer += commandPrepositionOn;
 		}
 	} else {
 		if (playerCommand == 2) {
@@ -1505,7 +1521,7 @@
 			processInventory(x, y + 8);
 			playerCommand = -1;
 			commandVar1 = 0;
-			strcpy(commandBuffer, "");
+			commandBuffer = "";
 		}
 	}
 
@@ -1761,8 +1777,9 @@
 						commandVar3[commandVar1] = si;
 						commandVar1++;
 
-						strcat(commandBuffer, " ");
-						strcat(commandBuffer, objectTable[si].name);
+						commandBuffer += " ";
+						commandBuffer += objectTable[si].name;
+						
 
 						isDrawCommandEnabled = 1;
 
@@ -1784,8 +1801,8 @@
 							playerCommand = -1;
 
 							commandVar1 = 0;
-							strcpy(commandBuffer, "");
-							renderer->setCommand("");
+							commandBuffer = "";
+							renderer->setCommand(commandBuffer);
 						}
 					} else {
 						globalVars[VAR_MOUSE_X_POS] = mouseX;
@@ -1806,13 +1823,7 @@
 
 				if (commandVar2 != objIdx) {
 					if (objIdx != -1) {
-						char command[256];
-
-						strcpy(command, commandBuffer);
-						strcat(command, " ");
-						strcat(command, objectTable[objIdx].name);
-
-						renderer->setCommand(command);
+						renderer->setCommand(commandBuffer + " " + objectTable[objIdx].name);
 					} else {
 						isDrawCommandEnabled = 1;
 					}

Modified: scummvm/trunk/engines/cine/various.h
===================================================================
--- scummvm/trunk/engines/cine/various.h	2008-08-11 23:20:10 UTC (rev 33792)
+++ scummvm/trunk/engines/cine/various.h	2008-08-12 00:13:27 UTC (rev 33793)
@@ -33,6 +33,9 @@
 
 namespace Cine {
 
+// Maximum size of the command buffer including the trailing zero
+#define kMaxCommandBufferSize 80
+
 void initLanguage(Common::Language lang);
 
 int16 makeMenuChoice(const CommandeType commandList[], uint16 height, uint16 X, uint16 Y, uint16 width, bool recheckValue = false);
@@ -85,7 +88,7 @@
 
 extern int16 playerCommand;
 
-extern char commandBuffer[80];
+extern Common::String commandBuffer;
 
 extern char currentPrcName[20];
 extern char currentRelName[20];


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