From 47d5b6ead7b7bb158261203d167ac3f3ea6ec277 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Thu, 8 Mar 2018 20:59:40 -0500 Subject: [PATCH] As suggested, extract strlen calls from sizes into variables so it isn't called twice --- Engine/source/T3D/components/component.cpp | 5 +- Engine/source/T3D/fx/particle.cpp | 5 +- Engine/source/T3D/fx/particleEmitter.cpp | 5 +- Engine/source/afx/afxMagicMissile.cpp | 5 +- Engine/source/afx/ce/afxParticleEmitter.cpp | 15 +++-- Engine/source/afx/xm/afxXM_PathConform.cpp | 5 +- Engine/source/app/badWordFilter.cpp | 5 +- Engine/source/app/net/serverQuery.cpp | 55 +++++++++++-------- Engine/source/cinterface/cinterface.cpp | 5 +- Engine/source/console/CMDscan.cpp | 5 +- Engine/source/console/CMDscan.l | 5 +- Engine/source/console/astAlloc.cpp | 5 +- Engine/source/console/console.cpp | 5 +- Engine/source/console/consoleFunctions.cpp | 15 +++-- Engine/source/console/fileSystemFunctions.cpp | 10 ++-- Engine/source/console/simObjectMemento.cpp | 5 +- Engine/source/core/stringTable.cpp | 5 +- Engine/source/core/strings/findMatch.cpp | 5 +- .../source/core/strings/stringFunctions.cpp | 5 +- Engine/source/core/util/zip/centralDir.cpp | 5 +- Engine/source/gfx/gfxStructs.cpp | 5 +- .../source/gui/controls/guiAnimBitmapCtrl.cpp | 5 +- Engine/source/i18n/lang.cpp | 35 +++++++----- .../source/persistence/taml/tamlWriteNode.h | 5 +- .../source/platformWin32/winDInputDevice.cpp | 5 +- Engine/source/platformWin32/winRedbook.cpp | 5 +- .../x86UNIXOGLVideo.client.cpp | 5 +- .../source/platformX86UNIX/x86UNIXRedbook.cpp | 5 +- Engine/source/sim/actionMap.cpp | 5 +- Engine/source/sim/netStringTable.cpp | 10 ++-- Engine/source/sqlite/SQLiteObject.cpp | 10 ++-- Engine/source/util/messaging/eventManager.cpp | 5 +- Engine/source/util/undo.cpp | 10 ++-- 33 files changed, 171 insertions(+), 114 deletions(-) diff --git a/Engine/source/T3D/components/component.cpp b/Engine/source/T3D/components/component.cpp index 1ef7904e9..c7f9dcc2c 100644 --- a/Engine/source/T3D/components/component.cpp +++ b/Engine/source/T3D/components/component.cpp @@ -547,8 +547,9 @@ const char * Component::getDescriptionText(const char *desc) // [tom, 1/12/2007] If it isn't a file, just do it the easy way if (!Platform::isFile(desc)) { - newDesc = new char[dStrlen(desc) + 1]; - dStrcpy(newDesc, desc, dStrlen(desc) + 1); + dsize_t newDescLen = dStrlen(desc) + 1; + newDesc = new char[newDescLen]; + dStrcpy(newDesc, desc, newDescLen); return newDesc; } diff --git a/Engine/source/T3D/fx/particle.cpp b/Engine/source/T3D/fx/particle.cpp index a528af0d1..66539ab24 100644 --- a/Engine/source/T3D/fx/particle.cpp +++ b/Engine/source/T3D/fx/particle.cpp @@ -594,8 +594,9 @@ bool ParticleData::preload(bool server, String &errorStr) animTexFrames.clear(); - char* tokCopy = new char[dStrlen(animTexFramesString) + 1]; - dStrcpy(tokCopy, animTexFramesString, dStrlen(animTexFramesString) + 1); + dsize_t tokLen = dStrlen(animTexFramesString) + 1; + char* tokCopy = new char[tokLen]; + dStrcpy(tokCopy, animTexFramesString, tokLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) diff --git a/Engine/source/T3D/fx/particleEmitter.cpp b/Engine/source/T3D/fx/particleEmitter.cpp index 00dbadb97..cab153574 100644 --- a/Engine/source/T3D/fx/particleEmitter.cpp +++ b/Engine/source/T3D/fx/particleEmitter.cpp @@ -608,8 +608,9 @@ bool ParticleEmitterData::onAdd() // First we parse particleString into a list of particle name tokens Vector dataBlocks(__FILE__, __LINE__); - char* tokCopy = new char[dStrlen(particleString) + 1]; - dStrcpy(tokCopy, particleString, dStrlen(particleString) + 1); + dsize_t tokLen = dStrlen(particleString) + 1; + char* tokCopy = new char[tokLen]; + dStrcpy(tokCopy, particleString, tokLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) diff --git a/Engine/source/afx/afxMagicMissile.cpp b/Engine/source/afx/afxMagicMissile.cpp index 690e3c74b..be42a9941 100644 --- a/Engine/source/afx/afxMagicMissile.cpp +++ b/Engine/source/afx/afxMagicMissile.cpp @@ -446,8 +446,9 @@ bool afxMagicMissileData::onAdd() Vector dataBlocks(__FILE__, __LINE__); // make a copy of points_string - char* tokCopy = new char[dStrlen(wiggle_axis_string) + 1]; - dStrcpy(tokCopy, wiggle_axis_string, dStrlen(wiggle_axis_string) + 1); + dsize_t tokCopyLen = dStrlen(wiggle_axis_string) + 1; + char* tokCopy = new char[tokCopyLen]; + dStrcpy(tokCopy, wiggle_axis_string, tokCopyLen); // extract tokens one by one, adding them to dataBlocks char* currTok = dStrtok(tokCopy, " \t"); diff --git a/Engine/source/afx/ce/afxParticleEmitter.cpp b/Engine/source/afx/ce/afxParticleEmitter.cpp index 2f7643c8f..1d76b2475 100644 --- a/Engine/source/afx/ce/afxParticleEmitter.cpp +++ b/Engine/source/afx/ce/afxParticleEmitter.cpp @@ -141,8 +141,9 @@ bool afxParticleEmitterData::onAdd() if (tpaths_string != ST_NULLSTRING) { Vector dataBlocks(__FILE__, __LINE__); - char* tokCopy = new char[dStrlen(tpaths_string) + 1]; - dStrcpy(tokCopy, tpaths_string, dStrlen(tpaths_string) + 1); + dsize_t tokCopyLen = dStrlen(tpaths_string) + 1; + char* tokCopy = new char[tokCopyLen]; + dStrcpy(tokCopy, tpaths_string, tokCopyLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) @@ -467,8 +468,9 @@ bool afxParticleEmitterPathData::onAdd() if (epaths_string != ST_NULLSTRING) { Vector dataBlocks(__FILE__, __LINE__); - char* tokCopy = new char[dStrlen(epaths_string) + 1]; - dStrcpy(tokCopy, epaths_string, dStrlen(epaths_string) + 1); + dsize_t tokCopyLen = dStrlen(epaths_string) + 1; + char* tokCopy = new char[tokCopyLen]; + dStrcpy(tokCopy, epaths_string, tokCopyLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) @@ -552,8 +554,9 @@ void afxParticleEmitterPathData::onPerformSubstitutions() if (epaths_string != ST_NULLSTRING) { Vector dataBlocks(__FILE__, __LINE__); - char* tokCopy = new char[dStrlen(epaths_string) + 1]; - dStrcpy(tokCopy, epaths_string, dStrlen(epaths_string) + 1); + dsize_t tokCopyLen = dStrlen(epaths_string) + 1; + char* tokCopy = new char[tokCopyLen]; + dStrcpy(tokCopy, epaths_string, tokCopyLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) diff --git a/Engine/source/afx/xm/afxXM_PathConform.cpp b/Engine/source/afx/xm/afxXM_PathConform.cpp index 3fde74699..07bd86d92 100644 --- a/Engine/source/afx/xm/afxXM_PathConform.cpp +++ b/Engine/source/afx/xm/afxXM_PathConform.cpp @@ -194,8 +194,9 @@ bool afxXM_PathConformData::onAdd() if (paths_string != ST_NULLSTRING) { Vector dataBlocks(__FILE__, __LINE__); - char* tokCopy = new char[dStrlen(paths_string) + 1]; - dStrcpy(tokCopy, paths_string, dStrlen(paths_string) + 1); + dsize_t tokCopyLen = dStrlen(paths_string) + 1; + char* tokCopy = new char[tokCopyLen]; + dStrcpy(tokCopy, paths_string, tokCopyLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) diff --git a/Engine/source/app/badWordFilter.cpp b/Engine/source/app/badWordFilter.cpp index 0a13a9c29..2983a8bb5 100644 --- a/Engine/source/app/badWordFilter.cpp +++ b/Engine/source/app/badWordFilter.cpp @@ -286,8 +286,9 @@ DefineEngineFunction(filterString, const char *, (const char* baseString, const else replaceStr = gBadWordFilter->getDefaultReplaceStr(); - char *ret = Con::getReturnBuffer(dStrlen(baseString) + 1); - dStrcpy(ret, baseString, dStrlen(baseString) + 1); + dsize_t retLen = dStrlen(baseString) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, baseString, retLen); gBadWordFilter->filterString(ret, replaceStr); return ret; } diff --git a/Engine/source/app/net/serverQuery.cpp b/Engine/source/app/net/serverQuery.cpp index 12a83c454..05d31e531 100644 --- a/Engine/source/app/net/serverQuery.cpp +++ b/Engine/source/app/net/serverQuery.cpp @@ -510,14 +510,16 @@ void queryMasterServer(U8 flags, const char* gameType, const char* missionType, // Update the active filter: if ( !sActiveFilter.gameType || dStrcmp( sActiveFilter.gameType, gameType ) != 0 ) { - sActiveFilter.gameType = (char*) dRealloc( sActiveFilter.gameType, dStrlen( gameType ) + 1 ); - dStrcpy( sActiveFilter.gameType, gameType, dStrlen(gameType) + 1 ); + dsize_t gameTypeLen = dStrlen(gameType) + 1; + sActiveFilter.gameType = (char*) dRealloc( sActiveFilter.gameType, gameTypeLen ); + dStrcpy( sActiveFilter.gameType, gameType, gameTypeLen ); } if ( !sActiveFilter.missionType || dStrcmp( sActiveFilter.missionType, missionType ) != 0 ) { - sActiveFilter.missionType = (char*) dRealloc( sActiveFilter.missionType, dStrlen( missionType ) + 1 ); - dStrcpy( sActiveFilter.missionType, missionType, dStrlen(missionType) + 1 ); + dsize_t missionTypeLen = dStrlen(missionType) + 1; + sActiveFilter.missionType = (char*) dRealloc( sActiveFilter.missionType, missionTypeLen ); + dStrcpy( sActiveFilter.missionType, missionType, missionTypeLen ); } sActiveFilter.queryFlags = flags | ServerFilter::NewStyleResponse; @@ -969,8 +971,9 @@ static void pushServerFavorites() Net::stringToAddress( addrString, &addr ); ServerInfo* si = findOrCreateServerInfo( &addr ); AssertFatal(si, "pushServerFavorites - failed to create Server Info!" ); - si->name = (char*) dRealloc( (void*) si->name, dStrlen( serverName ) + 1 ); - dStrcpy( si->name, serverName, dStrlen(serverName) + 1 ); + dsize_t nameLen = dStrlen(serverName) + 1; + si->name = (char*) dRealloc( (void*) si->name, nameLen ); + dStrcpy( si->name, serverName, nameLen ); si->isFavorite = true; pushPingRequest( &addr ); } @@ -1053,8 +1056,9 @@ void addFakeServers( S32 howMany ) newServer.maxPlayers = 64; char buf[256]; dSprintf( buf, 255, "Fake server #%d", sNumFakeServers ); - newServer.name = (char*) dMalloc( dStrlen( buf ) + 1 ); - dStrcpy( newServer.name, buf, strlen(buf) + 1 ); + dsize_t nameLen = dStrlen(buf) + 1; + newServer.name = (char*) dMalloc( nameLen ); + dStrcpy( newServer.name, buf, nameLen ); newServer.gameType = (char*) dMalloc( 5 ); dStrcpy( newServer.gameType, "Fake", 5 ); newServer.missionType = (char*) dMalloc( 16 ); @@ -1753,8 +1757,9 @@ static void handleGameMasterInfoRequest( const NetAddress* address, U32 key, U8 out->write( playerCount ); const char* guidList = Con::getVariable( "Server::GuidList" ); - char* buf = new char[dStrlen( guidList ) + 1]; - dStrcpy( buf, guidList, dStrlen(guidList) + 1 ); + dsize_t bufLen = dStrlen(guidList) + 1; + char* buf = new char[bufLen]; + dStrcpy( buf, guidList, bufLen ); char* temp = dStrtok( buf, "\t" ); temp8 = 0; for ( ; temp && temp8 < playerCount; temp8++ ) @@ -1948,8 +1953,9 @@ static void handleGamePingResponse( const NetAddress* address, BitStream* stream stream->readString( buf ); if ( !si->name ) { - si->name = (char*) dMalloc( dStrlen( buf ) + 1 ); - dStrcpy( si->name, buf, dStrlen(buf) + 1 ); + dsize_t bufLen = dStrlen(buf) + 1; + si->name = (char*) dMalloc(bufLen); + dStrcpy( si->name, buf, bufLen ); } // Set the server up to be queried: @@ -2050,8 +2056,9 @@ static void handleGameInfoResponse( const NetAddress* address, BitStream* stream stream->readString( stringBuf ); if ( !si->gameType || dStricmp( si->gameType, stringBuf ) != 0 ) { - si->gameType = (char*) dRealloc( (void*) si->gameType, dStrlen( stringBuf ) + 1 ); - dStrcpy( si->gameType, stringBuf, dStrlen(stringBuf) + 1 ); + dsize_t gameTypeLen = dStrlen(stringBuf) + 1; + si->gameType = (char*) dRealloc( (void*) si->gameType, gameTypeLen ); + dStrcpy( si->gameType, stringBuf, gameTypeLen ); // Test against the active filter: if ( applyFilter && dStricmp( sActiveFilter.gameType, "any" ) != 0 @@ -2067,8 +2074,9 @@ static void handleGameInfoResponse( const NetAddress* address, BitStream* stream stream->readString( stringBuf ); if ( !si->missionType || dStrcmp( si->missionType, stringBuf ) != 0 ) { - si->missionType = (char*) dRealloc( (void*) si->missionType, dStrlen( stringBuf ) + 1 ); - dStrcpy( si->missionType, stringBuf, dStrlen(stringBuf) + 1 ); + dsize_t missionTypeLen = dStrlen(stringBuf) + 1; + si->missionType = (char*) dRealloc( (void*) si->missionType, missionTypeLen ); + dStrcpy( si->missionType, stringBuf, missionTypeLen ); // Test against the active filter: if ( applyFilter && dStricmp( sActiveFilter.missionType, "any" ) != 0 @@ -2088,8 +2096,9 @@ static void handleGameInfoResponse( const NetAddress* address, BitStream* stream *temp = '\0'; if ( !si->missionName || dStrcmp( si->missionName, stringBuf ) != 0 ) { - si->missionName = (char*) dRealloc( (void*) si->missionName, dStrlen( stringBuf ) + 1 ); - dStrcpy( si->missionName, stringBuf, dStrlen(stringBuf) + 1 ); + dsize_t missionNameLen = dStrlen(stringBuf) + 1; + si->missionName = (char*) dRealloc( (void*) si->missionName, missionNameLen ); + dStrcpy( si->missionName, stringBuf, missionNameLen ); } // Get the server status: @@ -2157,16 +2166,18 @@ static void handleGameInfoResponse( const NetAddress* address, BitStream* stream stream->readString( stringBuf ); if ( !si->statusString || ( isUpdate && dStrcmp( si->statusString, stringBuf ) != 0 ) ) { - si->infoString = (char*) dRealloc( (void*) si->infoString, dStrlen( stringBuf ) + 1 ); - dStrcpy( si->infoString, stringBuf, dStrlen(stringBuf) + 1 ); + dsize_t infoLen = dStrlen(stringBuf) + 1; + si->infoString = (char*) dRealloc( (void*) si->infoString, infoLen ); + dStrcpy( si->infoString, stringBuf, infoLen ); } // Get the content string: readLongCString( stream, stringBuf ); if ( !si->statusString || ( isUpdate && dStrcmp( si->statusString, stringBuf ) != 0 ) ) { - si->statusString = (char*) dRealloc( (void*) si->statusString, dStrlen( stringBuf ) + 1 ); - dStrcpy( si->statusString, stringBuf, dStrlen(stringBuf) + 1 ); + dsize_t statusLen = dStrlen(stringBuf) + 1; + si->statusString = (char*) dRealloc( (void*) si->statusString, statusLen ); + dStrcpy( si->statusString, stringBuf, statusLen ); } // Update the server browser gui! diff --git a/Engine/source/cinterface/cinterface.cpp b/Engine/source/cinterface/cinterface.cpp index 4f6f1900c..aa0fae035 100644 --- a/Engine/source/cinterface/cinterface.cpp +++ b/Engine/source/cinterface/cinterface.cpp @@ -182,8 +182,9 @@ extern "C" { void torque_setexecutablepath(const char* directory) { - gExecutablePath = new char[dStrlen(directory)+1]; - dStrcpy(gExecutablePath, directory, dStrlen(directory)+1); + dsize_t pathLen = dStrlen(directory) + 1; + gExecutablePath = new char[pathLen]; + dStrcpy(gExecutablePath, directory, pathLen); } // set Torque 3D into web deployment mode (disable fullscreen exlusive mode, etc) diff --git a/Engine/source/console/CMDscan.cpp b/Engine/source/console/CMDscan.cpp index c780fd2a6..c30ac7bc9 100644 --- a/Engine/source/console/CMDscan.cpp +++ b/Engine/source/console/CMDscan.cpp @@ -2340,8 +2340,9 @@ static int Sc_ScanString(int ret) if (!collapseEscape(CMDtext + 1)) return -1; - char* buffer = (char*)consoleAlloc(dStrlen(CMDtext)); - dStrcpy(buffer, CMDtext + 1, dStrlen(CMDtext)); + dsize_t bufferLen = dStrlen(CMDtext); + char* buffer = (char*)consoleAlloc(bufferLen); + dStrcpy(buffer, CMDtext + 1, bufferLen); CMDlval.str = MakeToken< char* >(buffer, lineIndex); return ret; diff --git a/Engine/source/console/CMDscan.l b/Engine/source/console/CMDscan.l index c4bdc1bf3..e9069fe15 100644 --- a/Engine/source/console/CMDscan.l +++ b/Engine/source/console/CMDscan.l @@ -412,8 +412,9 @@ static int Sc_ScanString(int ret) if(!collapseEscape(CMDtext+1)) return -1; - char* buffer = ( char* ) consoleAlloc( dStrlen( CMDtext ) ); - dStrcpy( buffer, CMDtext + 1, dStrlen( CMDtext ) ); + dsize_t bufferLen = dStrlen( CMDtext ); + char* buffer = ( char* ) consoleAlloc( bufferLen ); + dStrcpy( buffer, CMDtext + 1, bufferLen ); CMDlval.str = MakeToken< char* >( buffer, lineIndex ); return ret; diff --git a/Engine/source/console/astAlloc.cpp b/Engine/source/console/astAlloc.cpp index e897af247..521b6dbcc 100644 --- a/Engine/source/console/astAlloc.cpp +++ b/Engine/source/console/astAlloc.cpp @@ -238,10 +238,11 @@ StrConstNode *StrConstNode::alloc(S32 lineNumber, char *str, bool tag, bool doc) StrConstNode *ret = (StrConstNode *)consoleAlloc(sizeof(StrConstNode)); constructInPlace(ret); ret->dbgLineNumber = lineNumber; - ret->str = (char *)consoleAlloc(dStrlen(str) + 1); + dsize_t retStrLen = dStrlen(str) + 1; + ret->str = (char *)consoleAlloc(retStrLen); ret->tag = tag; ret->doc = doc; - dStrcpy(ret->str, str, dStrlen(str) + 1); + dStrcpy(ret->str, str, retStrLen); return ret; } diff --git a/Engine/source/console/console.cpp b/Engine/source/console/console.cpp index be472f197..dc7dde340 100644 --- a/Engine/source/console/console.cpp +++ b/Engine/source/console/console.cpp @@ -646,8 +646,9 @@ static void _printf(ConsoleLogEntry::Level level, ConsoleLogEntry::Type type, co entry.mLevel = level; entry.mType = type; #ifndef TORQUE_SHIPPING // this is equivalent to a memory leak, turn it off in ship build - entry.mString = (const char *)consoleLogChunker.alloc(dStrlen(pos) + 1); - dStrcpy(const_cast(entry.mString), pos, dStrlen(pos) + 1); + dsize_t logStringLen = dStrlen(pos) + 1; + entry.mString = (const char *)consoleLogChunker.alloc(logStringLen); + dStrcpy(const_cast(entry.mString), pos, logStringLen); // This prevents infinite recursion if the console itself needs to // re-allocate memory to accommodate the new console log entry, and diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index 3ffe200ce..d32b30d31 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -585,8 +585,9 @@ DefineConsoleFunction( strlwr, const char*, ( const char* str ),, "@see strupr\n" "@ingroup Strings" ) { - char *ret = Con::getReturnBuffer(dStrlen(str) + 1); - dStrcpy(ret, str, dStrlen(str) + 1); + dsize_t retLen = dStrlen(str) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, str, retLen); return dStrlwr(ret); } @@ -602,8 +603,9 @@ DefineConsoleFunction( strupr, const char*, ( const char* str ),, "@see strlwr\n" "@ingroup Strings" ) { - char *ret = Con::getReturnBuffer(dStrlen(str) + 1); - dStrcpy(ret, str, dStrlen(str) + 1); + dsize_t retLen = dStrlen(str) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, str, retLen); return dStrupr(ret); } @@ -1826,8 +1828,9 @@ DefineEngineFunction( detag, const char*, ( const char* str ),, if( word == NULL ) return ""; - char* ret = Con::getReturnBuffer( dStrlen( word + 1 ) + 1 ); - dStrcpy( ret, word + 1, dStrlen(word + 1) + 1 ); + dsize_t retLen = dStrlen(word + 1) + 1; + char* ret = Con::getReturnBuffer(retLen); + dStrcpy( ret, word + 1, retLen ); return ret; } else diff --git a/Engine/source/console/fileSystemFunctions.cpp b/Engine/source/console/fileSystemFunctions.cpp index 0fdafec85..23ef01c24 100644 --- a/Engine/source/console/fileSystemFunctions.cpp +++ b/Engine/source/console/fileSystemFunctions.cpp @@ -617,8 +617,9 @@ DefineEngineFunction(fileBase, String, ( const char* fileName ),, path = szPathCopy; else path++; - char *ret = Con::getReturnBuffer(dStrlen(path) + 1); - dStrcpy(ret, path, dStrlen(path) + 1); + dsize_t retLen = dStrlen(path) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, path, retLen); char *ext = dStrrchr(ret, '.'); if(ext) *ext = 0; @@ -643,8 +644,9 @@ DefineEngineFunction(fileName, String, ( const char* fileName ),, name = szPathCopy; else name++; - char *ret = Con::getReturnBuffer(dStrlen(name) + 1); - dStrcpy(ret, name, dStrlen(name) + 1); + dsize_t retLen = dStrlen(name) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, name, retLen); return ret; } diff --git a/Engine/source/console/simObjectMemento.cpp b/Engine/source/console/simObjectMemento.cpp index 93a9db118..949349442 100644 --- a/Engine/source/console/simObjectMemento.cpp +++ b/Engine/source/console/simObjectMemento.cpp @@ -134,10 +134,11 @@ SimObject *SimObjectMemento::restore() const return NULL; U32 numCharsToLeftParen = pLeftParen - mState; - tempBuffer = ( char* ) dMalloc( dStrlen( mState ) + uniqueNameLen + 1 ); + dsize_t tempBufferLen = dStrlen(mState) + uniqueNameLen + 1; + tempBuffer = ( char* ) dMalloc( tempBufferLen ); dMemcpy( tempBuffer, mState, numCharsToLeftParen ); dMemcpy( &tempBuffer[ numCharsToLeftParen ], uniqueName, uniqueNameLen ); - dStrcpy( &tempBuffer[ numCharsToLeftParen + uniqueNameLen ], &mState[ numCharsToLeftParen ], dStrlen(mState) - numCharsToLeftParen + 1 ); + dStrcpy( &tempBuffer[ numCharsToLeftParen + uniqueNameLen ], &mState[ numCharsToLeftParen ], tempBufferLen - numCharsToLeftParen - uniqueNameLen ); } Con::evaluate( tempBuffer ); diff --git a/Engine/source/core/stringTable.cpp b/Engine/source/core/stringTable.cpp index 17f2ca235..d29519198 100644 --- a/Engine/source/core/stringTable.cpp +++ b/Engine/source/core/stringTable.cpp @@ -142,10 +142,11 @@ StringTableEntry _StringTable::insert(const char* _val, const bool caseSens) } char *ret = 0; if(!*walk) { + dsize_t valLen = dStrlen(val) + 1; *walk = (Node *) mempool.alloc(sizeof(Node)); (*walk)->next = 0; - (*walk)->val = (char *) mempool.alloc(dStrlen(val) + 1); - dStrcpy((*walk)->val, val, dStrlen(val) + 1); + (*walk)->val = (char *) mempool.alloc(valLen); + dStrcpy((*walk)->val, val, valLen); ret = (*walk)->val; itemCount ++; } diff --git a/Engine/source/core/strings/findMatch.cpp b/Engine/source/core/strings/findMatch.cpp index bfa7d5a3b..97829a5ca 100644 --- a/Engine/source/core/strings/findMatch.cpp +++ b/Engine/source/core/strings/findMatch.cpp @@ -71,8 +71,9 @@ void FindMatch::setExpression( const char *_expression ) { delete [] expression; - expression = new char[dStrlen(_expression) + 1]; - dStrcpy(expression, _expression, dStrlen(_expression) + 1); + dsize_t expressionLen = dStrlen(_expression) + 1; + expression = new char[expressionLen]; + dStrcpy(expression, _expression, expressionLen); dStrupr(expression); } diff --git a/Engine/source/core/strings/stringFunctions.cpp b/Engine/source/core/strings/stringFunctions.cpp index 668c9d649..77f7214d0 100644 --- a/Engine/source/core/strings/stringFunctions.cpp +++ b/Engine/source/core/strings/stringFunctions.cpp @@ -215,8 +215,9 @@ S32 dStrnatcasecmp(const nat_char* a, const nat_char* b) { char *dStrdup_r(const char *src, const char *fileName, dsize_t lineNumber) { - char *buffer = (char *) dMalloc_r(dStrlen(src) + 1, fileName, lineNumber); - dStrcpy(buffer, src, dStrlen(src) + 1); + dsize_t bufferLen = dStrlen(src) + 1; + char *buffer = (char *) dMalloc_r(bufferLen, fileName, lineNumber); + dStrcpy(buffer, src, bufferLen); return buffer; } diff --git a/Engine/source/core/util/zip/centralDir.cpp b/Engine/source/core/util/zip/centralDir.cpp index bf5bef92e..7646bac7a 100644 --- a/Engine/source/core/util/zip/centralDir.cpp +++ b/Engine/source/core/util/zip/centralDir.cpp @@ -177,8 +177,9 @@ bool CentralDir::write(Stream *stream) void CentralDir::setFileComment(const char *comment) { SAFE_DELETE_ARRAY(mFileComment); - mFileComment = new char [dStrlen(comment)+1]; - dStrcpy(mFileComment, comment, dStrlen(comment)+1); + dsize_t commentLen = dStrlen(comment) + 1; + mFileComment = new char [commentLen]; + dStrcpy(mFileComment, comment, commentLen); } //----------------------------------------------------------------------------- diff --git a/Engine/source/gfx/gfxStructs.cpp b/Engine/source/gfx/gfxStructs.cpp index ff8726b8b..7f64c6ee6 100644 --- a/Engine/source/gfx/gfxStructs.cpp +++ b/Engine/source/gfx/gfxStructs.cpp @@ -39,8 +39,9 @@ void GFXVideoMode::parseFromString( const char *str ) return; // Copy the string, as dStrtok is destructive - char *tempBuf = new char[dStrlen( str ) + 1]; - dStrcpy( tempBuf, str, dStrlen(str) + 1 ); + dsize_t tempBufLen = dStrlen(str) + 1; + char *tempBuf = new char[tempBufLen]; + dStrcpy( tempBuf, str, tempBufLen ); #define PARSE_ELEM(type, var, func, tokParam, sep) \ if(const char *ptr = dStrtok( tokParam, sep)) \ diff --git a/Engine/source/gui/controls/guiAnimBitmapCtrl.cpp b/Engine/source/gui/controls/guiAnimBitmapCtrl.cpp index 1f29caddc..26ce32376 100644 --- a/Engine/source/gui/controls/guiAnimBitmapCtrl.cpp +++ b/Engine/source/gui/controls/guiAnimBitmapCtrl.cpp @@ -167,8 +167,9 @@ bool guiAnimBitmapCtrl::ptSetFrameRanges(void *object, const char *index, const pData->mCurFrameIndex = pData->mNumFrames; return true; } - char* tokCopy = new char[dStrlen(data) + 1]; - dStrcpy(tokCopy, data, dStrlen(data) + 1); + dsize_t tokLen = dStrlen(data) + 1; + char* tokCopy = new char[tokLen]; + dStrcpy(tokCopy, data, tokLen); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) diff --git a/Engine/source/i18n/lang.cpp b/Engine/source/i18n/lang.cpp index 3ed0d344c..7e1efe4a5 100644 --- a/Engine/source/i18n/lang.cpp +++ b/Engine/source/i18n/lang.cpp @@ -42,8 +42,9 @@ LangFile::LangFile(const UTF8 *langName /* = NULL */) if(langName) { - mLangName = new UTF8 [dStrlen(langName) + 1]; - dStrcpy(mLangName, langName, dStrlen(langName) + 1); + dsize_t langNameLen = dStrlen(langName) + 1; + mLangName = new UTF8 [langNameLen]; + dStrcpy(mLangName, langName, langNameLen); } else mLangName = NULL; @@ -136,8 +137,9 @@ const UTF8 * LangFile::getString(U32 id) U32 LangFile::addString(const UTF8 *str) { - UTF8 *newstr = new UTF8 [dStrlen(str) + 1]; - dStrcpy(newstr, str, dStrlen(str) + 1); + dsize_t newstrLen = dStrlen(str) + 1; + UTF8 *newstr = new UTF8 [newstrLen]; + dStrcpy(newstr, str, newstrLen); mStringTable.push_back(newstr); return mStringTable.size() - 1; } @@ -156,8 +158,9 @@ void LangFile::setString(U32 id, const UTF8 *str) SAFE_DELETE_ARRAY(mStringTable[id]); - UTF8 *newstr = new UTF8 [dStrlen(str) + 1]; - dStrcpy(newstr, str, dStrlen(str) + 1); + dsize_t newstrLen = dStrlen(str) + 1; + UTF8 *newstr = new UTF8 [newstrLen]; + dStrcpy(newstr, str, newstrLen); mStringTable[id] = newstr; } @@ -166,8 +169,9 @@ void LangFile::setLangName(const UTF8 *newName) if(mLangName) delete [] mLangName; - mLangName = new UTF8 [dStrlen(newName) + 1]; - dStrcpy(mLangName, newName, dStrlen(newName) + 1); + dsize_t langNameLen = dStrlen(newName) + 1; + mLangName = new UTF8 [langNameLen]; + dStrcpy(mLangName, newName, langNameLen); } void LangFile::setLangFile(const UTF8 *langFile) @@ -175,8 +179,9 @@ void LangFile::setLangFile(const UTF8 *langFile) if(mLangFile) delete [] mLangFile; - mLangFile = new UTF8 [dStrlen(langFile) + 1]; - dStrcpy(mLangFile, langFile, dStrlen(langFile) + 1); + dsize_t langFileLen = dStrlen(langFile) + 1; + mLangFile = new UTF8 [langFileLen]; + dStrcpy(mLangFile, langFile, langFileLen); } bool LangFile::activateLanguage() @@ -349,8 +354,9 @@ DefineConsoleMethod(LangTable, getString, const char *, (U32 id), , const char * str = (const char*)object->getString(id); if(str != NULL) { - char * ret = Con::getReturnBuffer(dStrlen(str) + 1); - dStrcpy(ret, str, dStrlen(str) + 1); + dsize_t retLen = dStrlen(str) + 1; + char * ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, str, retLen); return ret; } @@ -387,8 +393,9 @@ DefineConsoleMethod(LangTable, getLangName, const char *, (S32 langId), , "(int const char * str = (const char*)object->getLangName(langId); if(str != NULL) { - char * ret = Con::getReturnBuffer(dStrlen(str) + 1); - dStrcpy(ret, str, dStrlen(str) + 1); + dsize_t retLen = dStrlen(str) + 1; + char * ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, str, retLen); return ret; } diff --git a/Engine/source/persistence/taml/tamlWriteNode.h b/Engine/source/persistence/taml/tamlWriteNode.h index 015224589..b406a54d8 100644 --- a/Engine/source/persistence/taml/tamlWriteNode.h +++ b/Engine/source/persistence/taml/tamlWriteNode.h @@ -53,8 +53,9 @@ public: mName = name; // Allocate and copy the value. - mpValue = new char[ dStrlen(pValue)+1 ]; - dStrcpy( (char *)mpValue, pValue, dStrlen(pValue) + 1 ); + dsize_t valueLen = dStrlen(pValue) + 1; + mpValue = new char[ valueLen ]; + dStrcpy( (char *)mpValue, pValue, valueLen ); } diff --git a/Engine/source/platformWin32/winDInputDevice.cpp b/Engine/source/platformWin32/winDInputDevice.cpp index c2969c65c..9ce308090 100644 --- a/Engine/source/platformWin32/winDInputDevice.cpp +++ b/Engine/source/platformWin32/winDInputDevice.cpp @@ -1575,8 +1575,9 @@ const char* DInputDevice::getJoystickAxesString() } } - char* returnString = Con::getReturnBuffer( dStrlen( buf ) + 1 ); - dStrcpy( returnString, buf, dStrlen(buf) + 1 ); + dsize_t returnLen = dStrlen(buf) + 1; + char* returnString = Con::getReturnBuffer(returnLen); + dStrcpy( returnString, buf, returnLen ); return( returnString ); } diff --git a/Engine/source/platformWin32/winRedbook.cpp b/Engine/source/platformWin32/winRedbook.cpp index 40b030c64..beef38dd0 100644 --- a/Engine/source/platformWin32/winRedbook.cpp +++ b/Engine/source/platformWin32/winRedbook.cpp @@ -83,8 +83,9 @@ void installRedBookDevices() if(::GetDriveTypeA(str) == DRIVE_CDROM) { Win32RedBookDevice * device = new Win32RedBookDevice; - device->mDeviceName = new char[dStrlen(str) + 1]; - dStrcpy(device->mDeviceName, str, dStrlen(str) + 1); + dsize_t deviceNameLen = dStrlen(str) + 1; + device->mDeviceName = new char[deviceNameLen]; + dStrcpy(device->mDeviceName, str, deviceNameLen); RedBook::installDevice(device); } diff --git a/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp b/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp index 384aade9e..9db3236c5 100644 --- a/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp @@ -40,8 +40,9 @@ bool InitOpenGL() // Get the video settings from the prefs: const char* resString = Con::getVariable( "$pref::Video::resolution" ); - char* tempBuf = new char[dStrlen( resString ) + 1]; - dStrcpy( tempBuf, resString, dStrlen(resString) + 1 ); + dsize_t tempBufLen = dStrlen(resString) + 1; + char* tempBuf = new char[tempBufLen]; + dStrcpy( tempBuf, resString, tempBufLen ); char* temp = dStrtok( tempBuf, " x\0" ); U32 width = ( temp ? dAtoi( temp ) : 800 ); temp = dStrtok( NULL, " x\0" ); diff --git a/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp b/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp index 3484a56ce..d24902230 100644 --- a/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp @@ -101,8 +101,9 @@ void UnixRedBookDevice::setDeviceInfo(S32 deviceId, const char *deviceName) { #if !defined(__FreeBSD__) mDeviceId = deviceId; - mDeviceName = new char[dStrlen(deviceName) + 1]; - dStrcpy(mDeviceName, deviceName, dStrlen(deviceName) + 1); + dsize_t deviceNameLen = dStrlen(deviceName) + 1; + mDeviceName = new char[deviceNameLen]; + dStrcpy(mDeviceName, deviceName, deviceNameLen); #endif // !defined(__FreeBSD__) } diff --git a/Engine/source/sim/actionMap.cpp b/Engine/source/sim/actionMap.cpp index 1d0fbe8b5..ca2932e84 100644 --- a/Engine/source/sim/actionMap.cpp +++ b/Engine/source/sim/actionMap.cpp @@ -908,8 +908,9 @@ const char* ActionMap::getDeadZone( const char* device, const char* action ) { char buf[64]; dSprintf( buf, sizeof( buf ), "%g %g", mapNode->deadZoneBegin, mapNode->deadZoneEnd ); - char* returnString = Con::getReturnBuffer( dStrlen( buf ) + 1 ); - dStrcpy( returnString, buf, dStrlen(buf) + 1 ); + dsize_t returnLen = dStrlen(buf) + 1; + char* returnString = Con::getReturnBuffer( returnLen ); + dStrcpy( returnString, buf, returnLen ); return( returnString ); } else diff --git a/Engine/source/sim/netStringTable.cpp b/Engine/source/sim/netStringTable.cpp index c21377885..83a059eff 100644 --- a/Engine/source/sim/netStringTable.cpp +++ b/Engine/source/sim/netStringTable.cpp @@ -96,8 +96,9 @@ U32 NetStringTable::addString(const char *string) size = newSize; } table[e].refCount++; - table[e].string = (char *) allocator->alloc(dStrlen(string) + 1); - dStrcpy(table[e].string, string, dStrlen(string) + 1); + dsize_t stringLen = dStrlen(string) + 1; + table[e].string = (char *) allocator->alloc(stringLen); + dStrcpy(table[e].string, string, stringLen); table[e].next = hashTable[bucket]; hashTable[bucket] = e; table[e].link = firstValid; @@ -178,8 +179,9 @@ void NetStringTable::repack() const char *prevStr = table[walk].string; - table[walk].string = (char *) newAllocator->alloc(dStrlen(prevStr) + 1); - dStrcpy(table[walk].string, prevStr, dStrlen(prevStr) + 1); + dsize_t prevStrLen = dStrlen(prevStr) + 1; + table[walk].string = (char *) newAllocator->alloc(prevStrLen); + dStrcpy(table[walk].string, prevStr, prevStrLen); } delete allocator; allocator = newAllocator; diff --git a/Engine/source/sqlite/SQLiteObject.cpp b/Engine/source/sqlite/SQLiteObject.cpp index a2900ab30..4cba76720 100644 --- a/Engine/source/sqlite/SQLiteObject.cpp +++ b/Engine/source/sqlite/SQLiteObject.cpp @@ -157,13 +157,15 @@ S32 Callback(void *pArg, S32 argc, char **argv, char **columnNames) { // DBEUG CODE // Con::printf("%s = %s\n", columnNames[i], argv[i] ? argv[i] : "NULL"); - name = new char[dStrlen(columnNames[i]) + 1]; - dStrcpy(name, columnNames[i], dStrlen(columnNames[i]) + 1); + dsize_t columnNameLen = dStrlen(columnNames[i]) + 1; + name = new char[columnNameLen]; + dStrcpy(name, columnNames[i], columnNameLen); pRow->vColumnNames.push_back(name); if (argv[i]) { - value = new char[dStrlen(argv[i]) + 1]; - dStrcpy(value, argv[i], dStrlen(argv[i]) + 1); + dsize_t valueLen = dStrlen(argv[i]) + 1; + value = new char[valueLen]; + dStrcpy(value, argv[i], valueLen); pRow->vColumnValues.push_back(value); } else diff --git a/Engine/source/util/messaging/eventManager.cpp b/Engine/source/util/messaging/eventManager.cpp index 5463e1efc..0edfa98fc 100644 --- a/Engine/source/util/messaging/eventManager.cpp +++ b/Engine/source/util/messaging/eventManager.cpp @@ -288,8 +288,9 @@ bool EventManager::subscribe(SimObject *callbackObj, const char* event, const ch } else { - cb = new char[dStrlen(callback) + 1]; - dStrcpy(cb, callback, dStrlen(callback) + 1); + dsize_t cbLen = dStrlen(callback) + 1; + cb = new char[cbLen]; + dStrcpy(cb, callback, cbLen); } // Create the subscriber object. diff --git a/Engine/source/util/undo.cpp b/Engine/source/util/undo.cpp index 11334a793..7ea0acc8c 100644 --- a/Engine/source/util/undo.cpp +++ b/Engine/source/util/undo.cpp @@ -545,8 +545,9 @@ DefineConsoleMethod(UndoManager, getNextUndoName, const char *, (),, "UndoManage const char *name = object->getNextUndoName(); if(!name) return NULL; - char *ret = Con::getReturnBuffer(dStrlen(name) + 1); - dStrcpy(ret, name, dStrlen(name) + 1); + dsize_t retLen = dStrlen(name) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, name, retLen); return ret; } @@ -556,8 +557,9 @@ DefineConsoleMethod(UndoManager, getNextRedoName, const char *, (),, "UndoManage const char *name = object->getNextRedoName(); if(!name) return NULL; - char *ret = Con::getReturnBuffer(dStrlen(name) + 1); - dStrcpy(ret, name, dStrlen(name) + 1); + dsize_t retLen = dStrlen(name) + 1; + char *ret = Con::getReturnBuffer(retLen); + dStrcpy(ret, name, retLen); return ret; }