From 502d8c3fa03cf8049ca76e3f8ec3838c884134b5 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Sun, 16 Dec 2018 00:38:10 +0100 Subject: avoid potential crash with EmuDirectory if we somehow got no argv or an empty path --- src/libui_sdl/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libui_sdl') diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index ee6b80d..4f0d278 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -1315,7 +1315,7 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) EmuRunning = prevstatus; return; } - + int pos = strlen(file)-1; while (file[pos] != '/' && file[pos] != '\\' && pos > 0) pos--; strncpy(Config::LastROMFolder, file, pos); @@ -1566,6 +1566,7 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); + if (argc > 0 && strlen(argv[0]) > 0) { int len = strlen(argv[0]); while (len > 0) @@ -1578,6 +1579,11 @@ int main(int argc, char** argv) strncpy(EmuDirectory, argv[0], len); EmuDirectory[len] = '\0'; } + else + { + EmuDirectory = new char[2]; + strcpy(EmuDirectory, "."); + } // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); -- cgit v1.2.3