mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09: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:
parent
3102cac9d9
commit
2b4f3ab19e
1 changed files with 5 additions and 5 deletions
|
@ -39,7 +39,7 @@ static char levelDir[MAX_PATH] = {'\0'};
|
||||||
static char assetDir[MAX_PATH] = {'\0'};
|
static char assetDir[MAX_PATH] = {'\0'};
|
||||||
static char virtualMountPath[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_migrateSaveData(char* output);
|
||||||
static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation);
|
static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation);
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PLATFORM_getOSDirectory(output);
|
PLATFORM_getOSDirectory(output, sizeof(output));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mount our base user directory */
|
/* 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
|
#ifdef _WIN32
|
||||||
/* This block is here for compatibility, do not touch it! */
|
/* This block is here for compatibility, do not touch it! */
|
||||||
WCHAR utf16_path[MAX_PATH];
|
WCHAR utf16_path[MAX_PATH];
|
||||||
SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, utf16_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);
|
SDL_strlcat(output, "\\VVVVVV\\", MAX_PATH);
|
||||||
mkdir(output, 0777);
|
mkdir(output, 0777);
|
||||||
#else
|
#else
|
||||||
SDL_strlcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"), MAX_PATH);
|
SDL_strlcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"), output_size);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue