Skip to content

Commit

Permalink
fix segfault when passing invalid filename on command line (#276)
Browse files Browse the repository at this point in the history
* fix segfault when passing invalid filename on command line

* fix formatting
  • Loading branch information
mothcompute committed Jul 14, 2022
1 parent 59f0175 commit 6d5dafa
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/tracker/sdl/SDL_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <limits.h>
#include <errno.h>

#include <SDL.h>
#include "SDL_KeyTranslation.h"
Expand Down Expand Up @@ -971,13 +972,21 @@ int main(int argc, char *argv[])

if (loadFile)
{
PPSystemString newCwd = path.getCurrent();
path.change(oldCwd);
SendFile(realpath(loadFile, loadFileAbsPath));
path.change(newCwd);
pp_uint16 chr[3] = {VK_RETURN, 0, 0};
PPEvent event(eKeyDown, &chr, sizeof(chr));
RaiseEventSerialized(&event);
struct stat statBuf;
if (stat(loadFile, &statBuf) != 0)
{
fprintf(stderr, "could not open %s: %s\n", loadFile, strerror(errno));
}
else
{
PPSystemString newCwd = path.getCurrent();
path.change(oldCwd);
SendFile(realpath(loadFile, loadFileAbsPath));
path.change(newCwd);
pp_uint16 chr[3] = {VK_RETURN, 0, 0};
PPEvent event(eKeyDown, &chr, sizeof(chr));
RaiseEventSerialized(&event);
}
}

// Main event loop
Expand Down

0 comments on commit 6d5dafa

Please sign in to comment.