1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Pass size of output through instead of hardcoding it

Previously, this function had a bug due to failing to account for array
decay. My solution was to just repeat the MAX_PATH again. But in
hindsight I realize that's bad because it hardcodes it, and introduces
the opportunity for an error where we update the size of the original
path but not the size in the function.

So instead, just pass the size through to the function.
This commit is contained in:
Misa 2021-04-18 14:26:29 -07:00 committed by Ethan Lee
parent 3102cac9d9
commit 2b4f3ab19e

View file

@ -39,7 +39,7 @@ static char levelDir[MAX_PATH] = {'\0'};
static char assetDir[MAX_PATH] = {'\0'};
static char virtualMountPath[MAX_PATH] = {'\0'};
static void PLATFORM_getOSDirectory(char* output);
static void PLATFORM_getOSDirectory(char* output, const size_t output_size);
static void PLATFORM_migrateSaveData(char* output);
static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation);
@ -86,7 +86,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
}
else
{
PLATFORM_getOSDirectory(output);
PLATFORM_getOSDirectory(output, sizeof(output));
}
/* Mount our base user directory */
@ -707,17 +707,17 @@ void FILESYSTEM_enumerateLevelDirFileNames(
}
}
static void PLATFORM_getOSDirectory(char* output)
static void PLATFORM_getOSDirectory(char* output, const size_t output_size)
{
#ifdef _WIN32
/* This block is here for compatibility, do not touch it! */
WCHAR utf16_path[MAX_PATH];
SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, utf16_path);
WideCharToMultiByte(CP_UTF8, 0, utf16_path, -1, output, MAX_PATH, NULL, NULL);
WideCharToMultiByte(CP_UTF8, 0, utf16_path, -1, output, output_size, NULL, NULL);
SDL_strlcat(output, "\\VVVVVV\\", MAX_PATH);
mkdir(output, 0777);
#else
SDL_strlcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"), MAX_PATH);
SDL_strlcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"), output_size);
#endif
}