Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 8, 2024
1 parent ee2ec88 commit 2140829
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/Jazz2/Compatibility/JJ2Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ namespace Jazz2::Compatibility
i32tos(i / 8, numberBuffer);

StringView foundDot = path.findLastOr('.', path.end());
String extraLayersPath = fs::FindPathCaseInsensitive(String(path.prefix(foundDot.begin()) + "-MLLE-Data-"_s + numberBuffer + ".j2l"_s));
String extraLayersPath = fs::FindPathCaseInsensitive(path.prefix(foundDot.begin()) + "-MLLE-Data-"_s + numberBuffer + ".j2l"_s);

JJ2Level extraLayersFile;
if (extraLayersFile.Open(extraLayersPath, strictParser)) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/UI/Menu/HighscoresSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# include <switch.h>
#elif defined(DEATH_TARGET_UNIX)
# include <pwd.h>
# include <unistd.h>
#endif

using namespace Death::IO::Compression;
Expand Down
9 changes: 1 addition & 8 deletions Sources/Shared/Containers/StringConcatenable.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ namespace Death { namespace Containers {
typedef String ConvertTo;

static std::size_t size(const char a[N]) {
std::size_t n = N;
while (n > 0 && a[n - 1] == '\0') {
n--;
}
return n;
return strnlen(a, N);
}
static inline void appendTo(const char a[N], char*& out) {
while (*a != '\0') {
Expand All @@ -169,9 +165,6 @@ namespace Death { namespace Containers {
return std::strlen(a);
}
static inline void appendTo(const char* a, char*& out) {
if (a == nullptr) {
return;
}
while (*a != '\0') {
*out++ = *a++;
}
Expand Down
20 changes: 15 additions & 5 deletions Sources/Shared/IO/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,17 @@ namespace Death { namespace IO {
goto Retry;
# endif
std::size_t charsLeft = sizeof(_path) - (_fileNamePart - _path) - 1;
std::size_t fileLength = strlen(entry->d_name);
if (fileLength > charsLeft) {
# if defined(__FreeBSD__)
std::size_t fileNameLength = entry->d_namlen;
# else
std::size_t fileNameLength = strlen(entry->d_name);
# endif
if (fileNameLength > charsLeft) {
// Path is too long, skip this file
goto Retry;
}
strcpy(_fileNamePart, entry->d_name);
std::memcpy(_fileNamePart, entry->d_name, fileNameLength);
_fileNamePart[fileNameLength] = '\0';
} else {
_path[0] = '\0';
}
Expand Down Expand Up @@ -744,8 +749,13 @@ namespace Death { namespace IO {
struct dirent* entry = ::readdir(d);
while (entry != nullptr) {
if (::strcasecmp(c, entry->d_name) == 0) {
strcpy(&result[rl], entry->d_name);
rl += strlen(entry->d_name);
# if defined(__FreeBSD__)
std::size_t fileNameLength = entry->d_namlen;
# else
std::size_t fileNameLength = std::strlen(entry->d_name);
# endif
std::memcpy(&result[rl], entry->d_name, fileNameLength);
rl += fileNameLength;

::closedir(d);
d = ::opendir(result.data());
Expand Down
4 changes: 4 additions & 0 deletions Sources/Shared/IO/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ namespace Death { namespace IO {
}
#else
static Containers::String FindPathCaseInsensitive(const Containers::StringView path);

DEATH_ALWAYS_INLINE static Containers::String FindPathCaseInsensitive(Containers::String&& path) {
return FindPathCaseInsensitive(StringView{path});
}
#endif

/** @brief Combines together specified path components */
Expand Down

0 comments on commit 2140829

Please sign in to comment.