1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 22:18:30 +02:00

Clean up strcat()s/strcpy()s, EXCEPT for migrateSaveData()

strcat()s and strcpy()s have been replaced with SDL_snprintf() where
possible, to clearly convey the intent of just building a string that
looks a certain way, instead of spanning it out over multiple lines.

Where there's not really a good way to avoid strcat()/strcpy() (e.g. in
PLATFORM_getOSDirectory()), they will at least be replaced with
SDL_strlcat() and SDL_strlcpy(), which are safer functions and are less
likely to have issues with null termination.

I decided not to bother with PLATFORM_migrateSaveData(), because it's
going to be axed in 2.4 anyways.
This commit is contained in:
Misa 2020-08-07 00:08:16 -07:00 committed by Ethan Lee
parent ce2eba1649
commit 609ceb782c

View File

@ -47,13 +47,13 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
/* Determine the OS user directory */
if (baseDir && baseDir[0] != '\0')
{
strcpy(output, baseDir);
/* We later append to this path and assume it ends in a slash */
if (SDL_strcmp(output + SDL_strlen(output) - SDL_strlen(pathSep), pathSep) != 0)
{
strcat(output, pathSep);
}
bool trailing_pathsep = SDL_strcmp(baseDir + SDL_strlen(baseDir) - SDL_strlen(pathSep), pathSep) == 0;
SDL_snprintf(output, sizeof(output), "%s%s",
baseDir,
!trailing_pathsep ? pathSep : ""
);
}
else
{
@ -97,12 +97,14 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
/* Mount the stock content last */
if (assetsPath)
{
strcpy(output, assetsPath);
SDL_strlcpy(output, assetsPath, sizeof(output));
}
else
{
strcpy(output, PHYSFS_getBaseDir());
strcat(output, "data.zip");
SDL_snprintf(output, sizeof(output), "%s%s",
PHYSFS_getBaseDir(),
"data.zip"
);
}
if (!PHYSFS_mount(output, NULL, 1))
{
@ -350,9 +352,9 @@ void PLATFORM_getOSDirectory(char* output)
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);
strcat(output, "\\VVVVVV\\");
SDL_strlcat(output, "\\VVVVVV\\", sizeof(output));
#else
strcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"));
SDL_strlcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"), sizeof(output));
#endif
}