Stack allocation never happened, so explicitly allocate the path

This commit is contained in:
Sam Lantinga 2024-06-05 05:48:39 -07:00
parent 4836fd1e70
commit 7b14fcb4d9

View file

@ -577,13 +577,11 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
return SDL_IOFromFP(fp, SDL_TRUE); return SDL_IOFromFP(fp, SDL_TRUE);
} else { } else {
/* Try opening it from internal storage if it's a relative path */ /* Try opening it from internal storage if it's a relative path */
// !!! FIXME: why not just "char path[PATH_MAX];" char *path = NULL;
char *path = SDL_stack_alloc(char, PATH_MAX); SDL_asprintf(&path, "%s/%s", SDL_AndroidGetInternalStoragePath(), file);
if (path) { if (path) {
SDL_snprintf(path, PATH_MAX, "%s/%s",
SDL_AndroidGetInternalStoragePath(), file);
FILE *fp = fopen(path, mode); FILE *fp = fopen(path, mode);
SDL_stack_free(path); SDL_free(path);
if (fp) { if (fp) {
if (!IsRegularFileOrPipe(fp)) { if (!IsRegularFileOrPipe(fp)) {
fclose(fp); fclose(fp);