Przeglądaj źródła

* BugFix: Correct non-constant array allocations in the POSIX case insensitivity code.

Robert MacGregor 3 lat temu
rodzic
commit
444c9dcf41

+ 9 - 5
Engine/source/platformPOSIX/posixVolume.cpp

@@ -157,7 +157,7 @@ FileNodeRef PosixFileSystem::resolve(const Path& path)
 #ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
 #ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
    // Resolve the case sensitive filepath
    // Resolve the case sensitive filepath
    String::SizeType fileLength = file.length();
    String::SizeType fileLength = file.length();
-   UTF8 caseSensitivePath[fileLength + 1];
+   UTF8* caseSensitivePath = new UTF8[fileLength + 1];
    dMemcpy(caseSensitivePath, file.c_str(), fileLength);
    dMemcpy(caseSensitivePath, file.c_str(), fileLength);
    caseSensitivePath[fileLength] = 0x00;
    caseSensitivePath[fileLength] = 0x00;
    ResolvePathCaseInsensitive(caseSensitivePath, fileLength);
    ResolvePathCaseInsensitive(caseSensitivePath, fileLength);
@@ -167,17 +167,21 @@ FileNodeRef PosixFileSystem::resolve(const Path& path)
    String caseSensitiveFile = file;
    String caseSensitiveFile = file;
 #endif
 #endif
 
 
+   FileNodeRef result = 0;
    if (stat(caseSensitiveFile.c_str(),&info) == 0)
    if (stat(caseSensitiveFile.c_str(),&info) == 0)
    {
    {
       // Construct the appropriate object
       // Construct the appropriate object
       if (S_ISREG(info.st_mode))
       if (S_ISREG(info.st_mode))
-         return new PosixFile(path,caseSensitiveFile);
+         result = new PosixFile(path,caseSensitiveFile);
          
          
       if (S_ISDIR(info.st_mode))
       if (S_ISDIR(info.st_mode))
-         return new PosixDirectory(path,caseSensitiveFile);
+         result = new PosixDirectory(path,caseSensitiveFile);
    }
    }
-   
-   return 0;
+
+#ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
+   delete[] caseSensitivePath;
+#endif
+   return result;
 }
 }
 
 
 FileNodeRef PosixFileSystem::create(const Path& path, FileNode::Mode mode)
 FileNodeRef PosixFileSystem::create(const Path& path, FileNode::Mode mode)

+ 5 - 1
Engine/source/platformX86UNIX/x86UNIXFileio.cpp

@@ -1286,7 +1286,7 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
  {
  {
 #ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
 #ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
    dsize_t pathLength = dStrlen(path);
    dsize_t pathLength = dStrlen(path);
-   char caseSensitivePath[pathLength + 1];
+   char* caseSensitivePath = new char[pathLength + 1];
 
 
    // Load path into temporary buffer
    // Load path into temporary buffer
    dMemcpy(caseSensitivePath, path, pathLength);
    dMemcpy(caseSensitivePath, path, pathLength);
@@ -1298,6 +1298,10 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
 
 
    bool retVal = recurseDumpDirectories(caseSensitivePath, "", directoryVector, -1, depth, noBasePath);
    bool retVal = recurseDumpDirectories(caseSensitivePath, "", directoryVector, -1, depth, noBasePath);
    clearExcludedDirectories();
    clearExcludedDirectories();
+
+#ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
+   delete[] caseSensitivePath;
+#endif
    return retVal;
    return retVal;
  }
  }