From 36de7a90278a2d4e5b4707e6fc23c6ff4a5b6d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 29 Dec 2015 16:09:36 +0100 Subject: [PATCH] Fix warnings Some off-by-one errors, truncation warning fix, main() in posix.c no longer a stub. --- src/platform/linux.c | 2 +- src/platform/posix.c | 6 +----- src/util/util.c | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/platform/linux.c b/src/platform/linux.c index 22e3245fcb..98edb78e5e 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -57,8 +57,8 @@ void platform_get_exe_path(utf8 *outPath) } int exeDelimiterIndex = (int)(exeDelimiter - exePath); + exePath[exeDelimiterIndex] = '\0'; safe_strncpy(outPath, exePath, exeDelimiterIndex + 1); - outPath[exeDelimiterIndex] = '\0'; } bool platform_check_steam_overlay_attached() { diff --git a/src/platform/posix.c b/src/platform/posix.c index 8a09b85b6f..36d9844c15 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -50,10 +50,6 @@ utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 }; */ int main(int argc, const char **argv) { - //RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE) = hInstance; - //RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, LPSTR) = lpCmdLine; - - STUB(); int run_game = cmdline_run(argv, argc); if (run_game == 1) { @@ -372,7 +368,7 @@ int platform_enumerate_directories_begin(const utf8 *directory) char *npattern = malloc(length+1); int converted; converted = wcstombs(npattern, wpattern, length); - npattern[length] = '\0'; + npattern[length - 1] = '\0'; if (converted == MAX_PATH) { log_warning("truncated string %s", npattern); } diff --git a/src/util/util.c b/src/util/util.c index 60b4a6ca6c..cfd0566eb7 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -205,7 +205,7 @@ char *safe_strncpy(char * destination, const char * source, size_t size) if (!terminated) { result[size - 1] = '\0'; - log_warning("Truncating string %s to %d bytes.", destination, size); + log_warning("Truncating string \"%s\" to %d bytes.", result, size); } return result; }