[Scummvm-cvs-logs] SF.net SVN: scummvm:[40216] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Thu Apr 30 17:57:10 CEST 2009


Revision: 40216
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40216&view=rev
Author:   drmccoy
Date:     2009-04-30 15:57:10 +0000 (Thu, 30 Apr 2009)

Log Message:
-----------
Adding a strdup-like inline function

Modified Paths:
--------------
    scummvm/trunk/engines/gob/demos/demoplayer.cpp
    scummvm/trunk/engines/gob/detection.cpp
    scummvm/trunk/engines/gob/gob.h
    scummvm/trunk/engines/gob/videoplayer.cpp

Modified: scummvm/trunk/engines/gob/demos/demoplayer.cpp
===================================================================
--- scummvm/trunk/engines/gob/demos/demoplayer.cpp	2009-04-30 15:55:59 UTC (rev 40215)
+++ scummvm/trunk/engines/gob/demos/demoplayer.cpp	2009-04-30 15:57:10 UTC (rev 40216)
@@ -67,8 +67,7 @@
 	uint32 waitTime = 0;
 	char *file, *filePtr;
 
-	file = filePtr = new char[strlen(fileName) + 1];
-	strcpy(file, fileName);
+	file = filePtr = strdupcpy(fileName);
 
 	// Trimming spaces front
 	while (*file == ' ')
@@ -121,14 +120,9 @@
 }
 
 void DemoPlayer::playVideoDoubled() {
-	const char *fileNameOpened;
-	char *fileName;
+	const char *fileNameOpened = _vm->_vidPlayer->getFileName();
+	char *fileName = strdupcpy(fileNameOpened);
 
-	fileNameOpened = _vm->_vidPlayer->getFileName();
-
-	fileName = new char[strlen(fileNameOpened) + 1];
-	strcpy(fileName, fileNameOpened);
-
 	_vm->_vidPlayer->primaryClose();
 
 	if (_vm->_vidPlayer->primaryOpen(fileName, 0, -1, VideoPlayer::kFlagOtherSurface)) {

Modified: scummvm/trunk/engines/gob/detection.cpp
===================================================================
--- scummvm/trunk/engines/gob/detection.cpp	2009-04-30 15:55:59 UTC (rev 40215)
+++ scummvm/trunk/engines/gob/detection.cpp	2009-04-30 15:57:10 UTC (rev 40216)
@@ -3147,21 +3147,15 @@
 namespace Gob {
 
 void GobEngine::initGame(const GOBGameDescription *gd) {
-	if (gd->startTotBase == 0) {
-		_startTot = new char[10];
-		strcpy(_startTot, "intro.tot");
-	} else {
-		_startTot = new char[strlen(gd->startTotBase) + 1];
-		strcpy(_startTot, gd->startTotBase);
-	}
+	if (gd->startTotBase == 0)
+		_startTot = strdupcpy("intro.tot");
+	else
+		_startTot = strdupcpy(gd->startTotBase);
 
-	if (gd->startStkBase == 0) {
-		_startStk = new char[10];
-		strcpy(_startStk, "intro.stk");
-	} else {
-		_startStk = new char[strlen(gd->startStkBase) + 1];
-		strcpy(_startStk, gd->startStkBase);
-	}
+	if (gd->startStkBase == 0)
+		_startStk = strdupcpy("intro.stk");
+	else
+		_startStk = strdupcpy(gd->startStkBase);
 
 	_gameType = gd->gameType;
 	_features = gd->features;

Modified: scummvm/trunk/engines/gob/gob.h
===================================================================
--- scummvm/trunk/engines/gob/gob.h	2009-04-30 15:55:59 UTC (rev 40215)
+++ scummvm/trunk/engines/gob/gob.h	2009-04-30 15:57:10 UTC (rev 40216)
@@ -135,6 +135,19 @@
 	return dest;
 }
 
+inline char *strdupcpy(const char *str) {
+	if (!str)
+		return 0;
+
+	size_t len = strlen(str) + 1;
+
+	char *nstr = new char[len];
+
+	memcpy(nstr, str, len);
+
+	return nstr;
+}
+
 // A "smart" reference counting templated class
 template<typename T>
 class ReferenceCounter {

Modified: scummvm/trunk/engines/gob/videoplayer.cpp
===================================================================
--- scummvm/trunk/engines/gob/videoplayer.cpp	2009-04-30 15:55:59 UTC (rev 40215)
+++ scummvm/trunk/engines/gob/videoplayer.cpp	2009-04-30 15:57:10 UTC (rev 40216)
@@ -77,8 +77,7 @@
 		return false;
 	}
 
-	_fileName = new char[strlen(fileName) + 1];
-	strcpy(_fileName, fileName);
+	_fileName = strdupcpy(fileName);
 
 	_defaultX = _video->getX();
 	_defaultY = _video->getY();


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