Skip to content

Commit

Permalink
REVIEWED: GetDirectoryPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Oct 8, 2023
1 parent 3472a16 commit 1399037
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 1399037

Please sign in to comment.