Przeglądaj źródła

As suggested, extract strlen calls from sizes into variables so it isn't called twice

Glenn Smith 7 lat temu
rodzic
commit
6b024b21bf
33 zmienionych plików z 171 dodań i 114 usunięć
  1. 3 2
      Engine/source/T3D/components/component.cpp
  2. 3 2
      Engine/source/T3D/fx/particle.cpp
  3. 3 2
      Engine/source/T3D/fx/particleEmitter.cpp
  4. 3 2
      Engine/source/afx/afxMagicMissile.cpp
  5. 9 6
      Engine/source/afx/ce/afxParticleEmitter.cpp
  6. 3 2
      Engine/source/afx/xm/afxXM_PathConform.cpp
  7. 3 2
      Engine/source/app/badWordFilter.cpp
  8. 33 22
      Engine/source/app/net/serverQuery.cpp
  9. 3 2
      Engine/source/cinterface/cinterface.cpp
  10. 3 2
      Engine/source/console/CMDscan.cpp
  11. 3 2
      Engine/source/console/CMDscan.l
  12. 3 2
      Engine/source/console/astAlloc.cpp
  13. 3 2
      Engine/source/console/console.cpp
  14. 9 6
      Engine/source/console/consoleFunctions.cpp
  15. 6 4
      Engine/source/console/fileSystemFunctions.cpp
  16. 3 2
      Engine/source/console/simObjectMemento.cpp
  17. 3 2
      Engine/source/core/stringTable.cpp
  18. 3 2
      Engine/source/core/strings/findMatch.cpp
  19. 3 2
      Engine/source/core/strings/stringFunctions.cpp
  20. 3 2
      Engine/source/core/util/zip/centralDir.cpp
  21. 3 2
      Engine/source/gfx/gfxStructs.cpp
  22. 3 2
      Engine/source/gui/controls/guiAnimBitmapCtrl.cpp
  23. 21 14
      Engine/source/i18n/lang.cpp
  24. 3 2
      Engine/source/persistence/taml/tamlWriteNode.h
  25. 3 2
      Engine/source/platformWin32/winDInputDevice.cpp
  26. 3 2
      Engine/source/platformWin32/winRedbook.cpp
  27. 3 2
      Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp
  28. 3 2
      Engine/source/platformX86UNIX/x86UNIXRedbook.cpp
  29. 3 2
      Engine/source/sim/actionMap.cpp
  30. 6 4
      Engine/source/sim/netStringTable.cpp
  31. 6 4
      Engine/source/sqlite/SQLiteObject.cpp
  32. 3 2
      Engine/source/util/messaging/eventManager.cpp
  33. 6 4
      Engine/source/util/undo.cpp

+ 3 - 2
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;
    }

+ 3 - 2
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) 

+ 3 - 2
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<char*> 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) 

+ 3 - 2
Engine/source/afx/afxMagicMissile.cpp

@@ -446,8 +446,9 @@ bool afxMagicMissileData::onAdd()
       Vector<char*> 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");

+ 9 - 6
Engine/source/afx/ce/afxParticleEmitter.cpp

@@ -141,8 +141,9 @@ bool afxParticleEmitterData::onAdd()
   if (tpaths_string != ST_NULLSTRING) 
   {
     Vector<char*> 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<char*> 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<char*> 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) 

+ 3 - 2
Engine/source/afx/xm/afxXM_PathConform.cpp

@@ -194,8 +194,9 @@ bool afxXM_PathConformData::onAdd()
   if (paths_string != ST_NULLSTRING) 
   {
     Vector<char*> 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) 

+ 3 - 2
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;
 }

+ 33 - 22
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!

+ 3 - 2
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)

+ 3 - 2
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;

+ 3 - 2
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;

+ 3 - 2
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;
 }

+ 3 - 2
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<char*>(entry.mString), pos, dStrlen(pos) + 1);
+            dsize_t logStringLen = dStrlen(pos) + 1;
+            entry.mString = (const char *)consoleLogChunker.alloc(logStringLen);
+            dStrcpy(const_cast<char*>(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 

+ 9 - 6
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

+ 6 - 4
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;
 }
 

+ 3 - 2
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 );

+ 3 - 2
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 ++;
    }

+ 3 - 2
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);
 }
 

+ 3 - 2
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;
 }
 

+ 3 - 2
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);
 }
 
 //-----------------------------------------------------------------------------

+ 3 - 2
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)) \

+ 3 - 2
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)

+ 21 - 14
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;
 	}
 	

+ 3 - 2
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 );
         }
         
 

+ 3 - 2
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 );
 }
 

+ 3 - 2
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);
       }

+ 3 - 2
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" );

+ 3 - 2
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__)
 }
 

+ 3 - 2
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

+ 6 - 4
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;

+ 6 - 4
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

+ 3 - 2
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.

+ 6 - 4
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;
 }