Skip to content

Commit

Permalink
[bugfix] general: Delocalizing the xavaGetInstallDir() string, which …
Browse files Browse the repository at this point in the history
…fixes SIGSEGV on Windows
  • Loading branch information
nikp123 committed Aug 25, 2020
1 parent 25f12e5 commit be8caac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,11 @@ void load_config(char *configPath, void* params)
printf("Default config doesn't exist!\n"
"Trying to find a default config file...");

const char *installPath = xavaGetInstallDir();
char *installPath = xavaGetInstallDir();
// don't trust sizeof(), it's evil
char *targetFile = malloc(strlen(installPath)+strlen(configFile)+1);
strcpy(targetFile, installPath);
free(installPath);
strcat(targetFile, configFile);

// because the program is not priviledged, read-only only
Expand Down
7 changes: 4 additions & 3 deletions src/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ int xavaGetConfigDir(char *configPath) {
return 0;
}

const char *xavaGetInstallDir() {
char *xavaGetInstallDir() {
#ifdef __WIN32__
// Windows uses widechars internally
WCHAR wpath[MAX_PATH];
char path[MAX_PATH];
char *path = malloc(MAX_PATH);

// Get path of where the executable is installed
HMODULE hModule = GetModuleHandleW(NULL);
Expand All @@ -107,7 +107,8 @@ const char *xavaGetInstallDir() {
path[strlen(path)-executableNameSize] = '\0';
#else
// everything non-windows is simple as fuck, go look at the mess above
const char *path = PREFIX"/share/"PACKAGE"/";
const char *path = malloc(strlen(PREFIX"/share/"PACKAGE"/"));
strcpy(path, PREFIX"/share/"PACKAGE"/");
#endif
return path;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int xavaMkdir(char *dir);
int xavaGetConfigDir(char *configPath);
const char *xavaGetInstallDir(void);
char *xavaGetInstallDir(void);
unsigned long xavaSleep(unsigned long oldTime, int framerate);

0 comments on commit be8caac

Please sign in to comment.