Skip to content

Commit

Permalink
Use strlcpy and strlcat in the Mac port
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBuckley committed Sep 7, 2020
1 parent 8d2bc33 commit a893ad0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
38 changes: 19 additions & 19 deletions macosx/mac-file.mm
Original file line number Diff line number Diff line change
Expand Up @@ -231,38 +231,38 @@ static void AddFolderIcon (NSURL *fref, const char *folderName)
{
case '.srm':
case '.rtc':
strcpy(folderName, "SRAMs");
strlcpy(folderName, "SRAMs", sizeof(folderName));
break;

case '.frz':
strcpy(folderName, "Freezes");
strlcpy(folderName, "Freezes", sizeof(folderName));
break;

case '.spc':
strcpy(folderName, "SPCs");
strlcpy(folderName, "SPCs", sizeof(folderName));
break;

case '.cht':
strcpy(folderName, "Cheats");
strlcpy(folderName, "Cheats", sizeof(folderName));
break;

case '.ups':
case '.ips':
strcpy(folderName, "Patches");
strlcpy(folderName, "Patches", sizeof(folderName));
break;

case '.png':
strcpy(folderName, "Screenshots");
strlcpy(folderName, "Screenshots", sizeof(folderName));
break;

case '.dat':
case '.out':
case '.log':
strcpy(folderName, "Logs");
strlcpy(folderName, "Logs", sizeof(folderName));
break;

case '.bio': // dummy
strcpy(folderName, "BIOSes");
strlcpy(folderName, "BIOSes", sizeof(folderName));
break;
}

Expand Down Expand Up @@ -296,15 +296,15 @@ static void AddFolderIcon (NSURL *fref, const char *folderName)
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);

strcat(fname, inExt);
strlcat(fname, inExt, sizeof(fname));
_makepath(filePath[index], drive, dir, fname, "");
}
}
else
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);

strcat(fname, inExt);
strlcat(fname, inExt, sizeof(fname));
_makepath(filePath[index], drive, dir, fname, "");
}

Expand Down Expand Up @@ -394,7 +394,7 @@ void S9xCloseSnapshotFile (STREAM file)
{
static char s[PATH_MAX + 1];

strncpy(s, in, PATH_MAX + 1);
strlcpy(s, in, sizeof(s));
s[PATH_MAX] = 0;

size_t l = strlen(s);
Expand Down Expand Up @@ -422,14 +422,14 @@ void S9xCloseSnapshotFile (STREAM file)

switch (dirtype)
{
case SNAPSHOT_DIR: strcpy(inExt, ".frz"); break;
case SRAM_DIR: strcpy(inExt, ".srm"); break;
case SCREENSHOT_DIR: strcpy(inExt, ".png"); break;
case SPC_DIR: strcpy(inExt, ".spc"); break;
case CHEAT_DIR: strcpy(inExt, ".cht"); break;
case BIOS_DIR: strcpy(inExt, ".bio"); break;
case LOG_DIR: strcpy(inExt, ".log"); break;
default: strcpy(inExt, ".xxx"); break;
case SNAPSHOT_DIR: strlcpy(inExt, ".frz", sizeof(inExt)); break;
case SRAM_DIR: strlcpy(inExt, ".srm", sizeof(inExt)); break;
case SCREENSHOT_DIR: strlcpy(inExt, ".png", sizeof(inExt)); break;
case SPC_DIR: strlcpy(inExt, ".spc", sizeof(inExt)); break;
case CHEAT_DIR: strlcpy(inExt, ".cht", sizeof(inExt)); break;
case BIOS_DIR: strlcpy(inExt, ".bio", sizeof(inExt)); break;
case LOG_DIR: strlcpy(inExt, ".log", sizeof(inExt)); break;
default: strlcpy(inExt, ".xxx", sizeof(inExt)); break;
}

_splitpath(S9xGetFilename(inExt, dirtype), drive, dir, fname, ext);
Expand Down
12 changes: 6 additions & 6 deletions macosx/mac-musicbox.mm
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,20 @@ static void SPCPlayExec (void)

static void MusicBoxForceFreeze (void)
{
char filename[PATH_MAX + 1];
char filename[PATH_MAX + 1];

strcpy(filename, S9xGetFreezeFilename(999));
strcat(filename, ".tmp");
strlcpy(filename, S9xGetFreezeFilename(999), sizeof(filename));
strlcat(filename, ".tmp", sizeof(filename));

S9xFreezeGame(filename);
}

static void MusicBoxForceDefrost (void)
{
char filename[PATH_MAX + 1];
char filename[PATH_MAX + 1];

strcpy(filename, S9xGetFreezeFilename(999));
strcat(filename, ".tmp");
strlcpy(filename, S9xGetFreezeFilename(999), sizeof(filename));
strlcat(filename, ".tmp", sizeof(filename));

S9xUnfreezeGame(filename);
remove(filename);
Expand Down

0 comments on commit a893ad0

Please sign in to comment.