From 139903787b3bb9cf1e45bd55a8fcc3fa74a42515 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 8 Oct 2023 18:18:05 +0200 Subject: [PATCH] REVIEWED: `GetDirectoryPath()` --- src/rcore.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rcore.c b/src/rcore.c index e967820a15d4..44b7ee787e96 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1435,7 +1435,9 @@ const char *GetDirectoryPath(const char *filePath) else { // NOTE: Be careful, strncpy() is not safe, it does not care about '\0' - memcpy(dirPath + ((filePath[1] != ':') && (filePath[0] != '\\') && (filePath[0] != '/'))? 2 : 0, filePath, strlen(filePath) - (strlen(lastSlash) - 1)); + unsigned char *dirPathPtr = dirPath; + if ((filePath[1] != ':') && (filePath[0] != '\\') && (filePath[0] != '/')) dirPathPtr += 2; // Skip drive letter, "C:" + memcpy(dirPathPtr, filePath, strlen(filePath) - (strlen(lastSlash) - 1)); dirPath[strlen(filePath) - strlen(lastSlash) + ((filePath[1] != ':') && (filePath[0] != '\\') && (filePath[0] != '/'))? 2 : 0] = '\0'; // Add '\0' manually } }