1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-10 13:09:43 +01:00

Fix basedir trailing path separator check

The previous check by mwpenny had a few issues:

(a) It was completely overcomplicated for no good reason, and was
basically a Rube Goldberg machine. The original check was...

   (1) Creating an std::string of the last char of 'output'...
   (2) ...except instead of using the normal std::string constructor, it
       was using the one where you pass in a number and a char to create
       a string that's just that char repeated N times... except this
       was only used to create a 1-length string.
   (3) Converted that std::string to a C string.
   (4) Then passed it to strcmp(), despite the string at this point
       being only one byte and you could just compare the char values
       directly.

    The original check could've just been:
        output[SDL_strlen(output) - 1] == *pathSep

(b) Use of libc strcmp() and strlen() instead of SDL_strcmp() and
    SDL_strlen().

Now, actually, PHYSFS_getDirSeparator() happens to be a char array and
not a single char, so mwpenny was going in the right direction by using
strcmp() after all. Except it doesn't seem like he thought about the
fact that PHYSFS_getDirSeparator() could be multiple bytes instead of
one, and so he ended up making the first argument to strcmp() always be
a one-byte char array.

So there's issue (c), which is that it assumes the path separator is one
byte instead of multiple.

This commit fixes all of these issues with the trailing path separator
check.
This commit is contained in:
Misa 2020-08-06 23:08:09 -07:00 committed by Ethan Lee
parent d1938a151f
commit 7478b68dd7

View file

@ -50,7 +50,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
strcpy(output, baseDir);
/* We later append to this path and assume it ends in a slash */
if (strcmp(std::string(1, output[strlen(output) - 1]).c_str(), pathSep) != 0)
if (SDL_strcmp(output + SDL_strlen(output) - SDL_strlen(pathSep), pathSep) != 0)
{
strcat(output, pathSep);
}