diff --git a/Source/Engine/Platform/Android/AndroidFileSystem.cpp b/Source/Engine/Platform/Android/AndroidFileSystem.cpp index 298051f6e..2298e34b2 100644 --- a/Source/Engine/Platform/Android/AndroidFileSystem.cpp +++ b/Source/Engine/Platform/Android/AndroidFileSystem.cpp @@ -44,7 +44,6 @@ namespace bool DeleteUnixPathTree(const char* path) { size_t pathLength; - DIR* dir; struct stat statPath, statEntry; struct dirent* entry; @@ -59,7 +58,8 @@ namespace } // If not possible to read the directory for this user - if ((dir = opendir(path)) == nullptr) + DIR* dir = dir = opendir(path); + if (dir == nullptr) { // Cannot open directory return true; @@ -77,7 +77,7 @@ namespace // Determinate a full path of an entry char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); strcpy(full_path, path); strcat(full_path, "/"); strcat(full_path, entry->d_name); @@ -168,7 +168,6 @@ bool AndroidFileSystem::DirectoryGetFiles(Array& results, const String& bool AndroidFileSystem::GetChildDirectories(Array& results, const String& directory) { size_t pathLength; - DIR* dir; struct stat statPath, statEntry; struct dirent* entry; const StringAsANSI<> pathANSI(*directory, directory.Length()); @@ -185,7 +184,8 @@ bool AndroidFileSystem::GetChildDirectories(Array& results, const String } // If not possible to read the directory for this user - if ((dir = opendir(path)) == nullptr) + DIR* dir = opendir(path); + if (dir == nullptr) { // Cannot open directory return true; @@ -203,7 +203,7 @@ bool AndroidFileSystem::GetChildDirectories(Array& results, const String // Determinate a full path of an entry char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); strcpy(full_path, path); strcat(full_path, "/"); strcat(full_path, entry->d_name); @@ -381,7 +381,6 @@ out_error: bool AndroidFileSystem::getFilesFromDirectoryTop(Array& results, const char* path, const char* searchPattern) { size_t pathLength; - DIR* dir; struct stat statPath, statEntry; struct dirent* entry; @@ -396,7 +395,8 @@ bool AndroidFileSystem::getFilesFromDirectoryTop(Array& results, const c } // If not possible to read the directory for this user - if ((dir = opendir(path)) == nullptr) + DIR* dir = opendir(path); + if (dir == nullptr) { // Cannot open directory return true; @@ -432,7 +432,7 @@ bool AndroidFileSystem::getFilesFromDirectoryTop(Array& results, const c { // All files } - else if (searchPattern[0] == '*' && searchPatternLength < fullPathLength && StringUtils::Compare(fullPath + fullPathLength - searchPatternLength, searchPattern + 1) == 0) + else if (searchPattern[0] == '*' && searchPatternLength < fullPathLength && StringUtils::Compare(fullPath + fullPathLength - searchPatternLength + 1, searchPattern + 1) == 0) { // Path ending } @@ -458,7 +458,6 @@ bool AndroidFileSystem::getFilesFromDirectoryAll(Array& results, const c getFilesFromDirectoryTop(results, path, searchPattern); size_t pathLength; - DIR* dir; struct stat statPath, statEntry; struct dirent* entry; @@ -473,7 +472,8 @@ bool AndroidFileSystem::getFilesFromDirectoryAll(Array& results, const c } // If not possible to read the directory for this user - if ((dir = opendir(path)) == nullptr) + DIR* dir = opendir(path); + if (dir == nullptr) { // Cannot open directory return true; @@ -491,7 +491,7 @@ bool AndroidFileSystem::getFilesFromDirectoryAll(Array& results, const c // Determinate a full path of an entry char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); strcpy(full_path, path); strcat(full_path, "/"); strcat(full_path, entry->d_name); diff --git a/Source/Engine/Platform/Linux/LinuxFileSystem.cpp b/Source/Engine/Platform/Linux/LinuxFileSystem.cpp index 860805c9a..8fce4ea3a 100644 --- a/Source/Engine/Platform/Linux/LinuxFileSystem.cpp +++ b/Source/Engine/Platform/Linux/LinuxFileSystem.cpp @@ -108,7 +108,7 @@ bool DeleteUnixPathTree(const char* path) // Determinate a full path of an entry char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); strcpy(full_path, path); strcat(full_path, "/"); strcat(full_path, entry->d_name); @@ -211,7 +211,7 @@ bool LinuxFileSystem::GetChildDirectories(Array& results, const String& // Determinate a full path of an entry char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); strcpy(full_path, path); strcat(full_path, "/"); strcat(full_path, entry->d_name); @@ -373,7 +373,6 @@ out_error: bool LinuxFileSystem::getFilesFromDirectoryTop(Array& results, const char* path, const char* searchPattern) { size_t pathLength; - DIR* dir; struct stat statPath, statEntry; struct dirent* entry; @@ -388,7 +387,8 @@ bool LinuxFileSystem::getFilesFromDirectoryTop(Array& results, const cha } // If not possible to read the directory for this user - if ((dir = opendir(path)) == NULL) + DIR* dir = opendir(path); + if (dir == NULL) { // Cannot open directory return true; @@ -406,7 +406,7 @@ bool LinuxFileSystem::getFilesFromDirectoryTop(Array& results, const cha // Determinate a full path of an entry char fullPath[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(fullPath)); strcpy(fullPath, path); strcat(fullPath, "/"); strcat(fullPath, entry->d_name); @@ -424,7 +424,7 @@ bool LinuxFileSystem::getFilesFromDirectoryTop(Array& results, const cha { // All files } - else if (searchPattern[0] == '*' && searchPatternLength < fullPathLength && StringUtils::Compare(fullPath + fullPathLength - searchPatternLength, searchPattern + 1) == 0) + else if (searchPattern[0] == '*' && searchPatternLength < fullPathLength && StringUtils::Compare(fullPath + fullPathLength - searchPatternLength + 1, searchPattern + 1, searchPatternLength - 1) == 0) { // Path ending } @@ -483,7 +483,7 @@ bool LinuxFileSystem::getFilesFromDirectoryAll(Array& results, const cha // Determinate a full path of an entry char full_path[256]; - ASSERT(pathLength + strlen(entry->d_name) <= 255); + ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(full_path)); strcpy(full_path, path); strcat(full_path, "/"); strcat(full_path, entry->d_name);