Bladeren bron

Merge pull request #2323 from Areloch/getFieldValueCrashfix

Sanity check for calling getFieldValue
Areloch 6 jaren geleden
bovenliggende
commit
18f4e3172e
1 gewijzigde bestanden met toevoegingen van 4 en 1 verwijderingen
  1. 4 1
      Engine/source/console/simObject.cpp

+ 4 - 1
Engine/source/console/simObject.cpp

@@ -2834,13 +2834,16 @@ DefineEngineMethod( SimObject, getFieldValue, const char*, ( const char* fieldNa
    "@param index Optional parameter to specify the index of an array field separately.\n"
    "@param index Optional parameter to specify the index of an array field separately.\n"
    "@return The value of the given field or \"\" if undefined." )
    "@return The value of the given field or \"\" if undefined." )
 {
 {
+   const U32 nameLen = dStrlen( fieldName );
+   if (nameLen == 0)
+      return "";
+
    char fieldNameBuffer[ 1024 ];
    char fieldNameBuffer[ 1024 ];
    char arrayIndexBuffer[ 64 ];
    char arrayIndexBuffer[ 64 ];
    
    
    // Parse out index if the field is given in the form of 'name[index]'.
    // Parse out index if the field is given in the form of 'name[index]'.
    
    
    const char* arrayIndex = NULL;
    const char* arrayIndex = NULL;
-   const U32 nameLen = dStrlen( fieldName );
    if( fieldName[ nameLen - 1 ] == ']' )
    if( fieldName[ nameLen - 1 ] == ']' )
    {
    {
       const char* leftBracket = dStrchr( fieldName, '[' );
       const char* leftBracket = dStrchr( fieldName, '[' );