Stop walking a mod's folders at 32 levels, where each level cost a stack frame of about 18 KB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-09 05:57:18 -05:00
parent 443c4873fe
commit b9479507ed
2 changed files with 20 additions and 11 deletions

View File

@@ -36,20 +36,24 @@ static char dir[2048];
static char start_order[MAX_MODS][256]; // names in the scan's order, for mods_changed
// 1 when a file lies anywhere under path.
// Folders nest at most MOD_DEPTH deep below it: each level costs a stack frame, and the RomFS has no deeper paths.
#define MOD_DEPTH 32
typedef struct { const char *path; int found, depth; } HasFile;
static int has_file_cb(const char *name, int kind, uint64_t size, void *ctx);
static int has_file(const char *path) {
struct { const char *path; int found; } c = {path, 0};
static int has_file_at(const char *path, int depth) {
HasFile c = {path, 0, depth};
plat_fs_list(path, has_file_cb, &c);
return c.found;
}
static int has_file(const char *path) { return has_file_at(path, 0); }
static int has_file_cb(const char *name, int kind, uint64_t size, void *ctx) {
(void)size;
struct { const char *path; int found; } *c = ctx;
HasFile *c = ctx;
if (kind == PLAT_FS_FILE) {
c->found = 1;
} else if (kind == PLAT_FS_DIR) {
} else if (kind == PLAT_FS_DIR && c->depth < MOD_DEPTH) {
char sub[2100];
if (snprintf(sub, sizeof sub, "%s/%s", c->path, name) < (int)sizeof sub) c->found = has_file(sub);
if (snprintf(sub, sizeof sub, "%s/%s", c->path, name) < (int)sizeof sub) c->found = has_file_at(sub, c->depth + 1);
}
return !c->found;
}