Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SDL_GetBasePath() returning null. #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,15 @@ main(int argc, char **argv)

char *base_path = SDL_GetBasePath();

if (!base_path) {
base_path = SDL_strdup("./");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you need to allocate a copy of this string? The following should work:

base_path = "./"

This way, you don't have to SDL_free() later.

}

// This causes the emulator to load ROM data from the executable's directory when
// no ROM file is specified on the command line.
memcpy(rom_path, base_path, strlen(base_path) + 1);
strncpy(rom_path + strlen(rom_path), rom_filename, PATH_MAX - strlen(rom_path));
SDL_free(base_path);

argc--;
argv++;
Expand Down