diff --git a/src/cmdline/RootCommands.cpp b/src/cmdline/RootCommands.cpp index 5596d65b69..c9f947a76d 100644 --- a/src/cmdline/RootCommands.cpp +++ b/src/cmdline/RootCommands.cpp @@ -132,7 +132,7 @@ exitcode_t CommandLine::HandleCommandDefault() if (_openrctDataPath != NULL) { String::Set(gCustomOpenrctDataPath, sizeof(gCustomOpenrctDataPath), _openrctDataPath); - Memory::Free(gCustomOpenrctDataPath); + Memory::Free(_openrctDataPath); } return result; diff --git a/src/platform/posix.c b/src/platform/posix.c index 21e0c7b858..37ce88087d 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -192,7 +192,10 @@ bool platform_directory_delete(const utf8 *path) chp = fts_children(ftsp, 0); if (chp == NULL) { log_verbose("No files to traverse, deleting directory %s", path); - remove(path); + if (remove(path) != 0) + { + log_error("Failed to remove %s, errno = %d", path, errno); + } free(ourPath); return true; // No files to traverse } @@ -227,12 +230,9 @@ bool platform_directory_delete(const utf8 *path) bool platform_lock_single_instance() { char pidFilePath[MAX_PATH]; - char separator = platform_get_path_separator(); - strncpy(pidFilePath, _userDataDirectoryPath, MAX_PATH); - strncat(pidFilePath, &separator, 1); - strncat(pidFilePath, SINGLE_INSTANCE_MUTEX_NAME, - MAX_PATH - strnlen(pidFilePath, MAX_PATH) - 1); + safe_strncpy(pidFilePath, _userDataDirectoryPath, sizeof(pidFilePath)); + safe_strcat_path(pidFilePath, SINGLE_INSTANCE_MUTEX_NAME, sizeof(pidFilePath)); // We will never close this file manually. The operating system will // take care of that, because flock keeps the lock as long as the @@ -576,10 +576,11 @@ bool platform_file_copy(const utf8 *srcPath, const utf8 *dstPath, bool overwrite if (overwrite) { dstFile = fopen(dstPath, "wb"); } else { + // Portability note: check your libc's support for "wbx" dstFile = fopen(dstPath, "wbx"); } - if (dstFile != NULL) { + if (dstFile == NULL) { if (errno == EEXIST) { log_warning("platform_file_copy: Not overwriting %s, because overwrite flag == false", dstPath); return 0; @@ -591,7 +592,7 @@ bool platform_file_copy(const utf8 *srcPath, const utf8 *dstPath, bool overwrite // Open both files and check whether they are opened correctly FILE *srcFile = fopen(srcPath, "rb"); - if (!srcFile) { + if (srcFile == NULL) { fclose(dstFile); log_error("Could not open source file %s for copying", srcPath); return 0; diff --git a/src/util/util.c b/src/util/util.c index bc18de7d65..48eac67c3b 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -265,7 +265,7 @@ char *safe_strcat_path(char *destination, const char *source, size_t size) { const char pathSeparator = platform_get_path_separator(); - size_t length = strlen(destination); + size_t length = strnlen(destination, size); if (length >= size - 1) { return destination; }