From 4080eef6a709390a5355d9bb1e7706e70117bf77 Mon Sep 17 00:00:00 2001 From: Ari Sundholm Date: Sat, 9 Sep 2017 14:10:56 +0300 Subject: [PATCH] gtk, unix: fixes to unbreak build and loading ROMs --- gtk/src/gtk_file.cpp | 36 ++++++++++++++++++++++++------------ msu1.cpp | 2 +- unix/unix.cpp | 34 ++++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/gtk/src/gtk_file.cpp b/gtk/src/gtk_file.cpp index b6607f75..2722719d 100644 --- a/gtk/src/gtk_file.cpp +++ b/gtk/src/gtk_file.cpp @@ -33,7 +33,8 @@ _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext) char *slash = strrchr ((char *) path, SLASH_CHAR); char *dot = strrchr ((char *) path, '.'); - *drive = '\0'; + if (drive) + *drive = '\0'; if (dot && slash && dot < slash) { @@ -42,33 +43,44 @@ _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext) if (!slash) { - *dir = '\0'; - strcpy (fname, path); + if (dir) + *dir = '\0'; + if (fname) + strcpy (fname, path); if (dot) { - fname[dot - path] = '\0'; - strcpy (ext, dot + 1); + if (fname) + fname[dot - path] = '\0'; + if (ext) + strcpy (ext, dot + 1); } else { - *ext = '\0'; + if (ext) + *ext = '\0'; } } else { - strcpy (dir, path); - dir[slash - path] = '\0'; - strcpy (fname, slash + 1); + if (dir) { + strcpy (dir, path); + dir[slash - path] = '\0'; + } + if (fname) + strcpy (fname, slash + 1); if (dot) { - fname[(dot - slash) - 1] = '\0'; - strcpy (ext, dot + 1); + if (fname) + fname[(dot - slash) - 1] = '\0'; + if (ext) + strcpy (ext, dot + 1); } else { - *ext = '\0'; + if (ext) + *ext = '\0'; } } diff --git a/msu1.cpp b/msu1.cpp index bf0a96a1..341f5226 100644 --- a/msu1.cpp +++ b/msu1.cpp @@ -388,7 +388,7 @@ bool S9xMSU1ROMExists(void) } #ifdef UNZIP_SUPPORT char ext[_MAX_EXT + 1]; - _splitpath(Memory.ROMFilename, nullptr, nullptr, nullptr, ext); + _splitpath(Memory.ROMFilename, NULL, NULL, NULL, ext); if (!strcasecmp(ext, ".msu1")) return true; diff --git a/unix/unix.cpp b/unix/unix.cpp index b44e0617..89360e70 100644 --- a/unix/unix.cpp +++ b/unix/unix.cpp @@ -354,7 +354,8 @@ static void ReadJoysticks (void); void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext) { - *drive = 0; + if (drive) + *drive = 0; const char *slash = strrchr(path, SLASH_CHAR), *dot = strrchr(path, '.'); @@ -364,31 +365,40 @@ void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ex if (!slash) { - *dir = 0; + if (dir) + *dir = 0; - strcpy(fname, path); + if (fname) + strcpy(fname, path); if (dot) { - fname[dot - path] = 0; - strcpy(ext, dot + 1); + if (fname) + fname[dot - path] = 0; + if (ext) + strcpy(ext, dot + 1); } - else + else if (ext) *ext = 0; } else { - strcpy(dir, path); - dir[slash - path] = 0; + if (dir) { + strcpy(dir, path); + dir[slash - path] = 0; + } - strcpy(fname, slash + 1); + if (fname) + strcpy(fname, slash + 1); if (dot) { - fname[dot - slash - 1] = 0; - strcpy(ext, dot + 1); + if (fname) + fname[dot - slash - 1] = 0; + if (ext) + strcpy(ext, dot + 1); } - else + else if (ext) *ext = 0; } }