diff --git a/clang/parse/auto_dup.c b/clang/parse/auto_dup.c index d0aacb9..bfac2f2 100644 --- a/clang/parse/auto_dup.c +++ b/clang/parse/auto_dup.c @@ -62,7 +62,7 @@ fn void auto_dup_go(u64 loc, u32 lvl, u32 base, u32 *use, u32 n, u32 lab, u8 tgt } // Shift outer refs - if ((tg == BJV || tg == BJ0 || tg == BJ1) && vl > base) { + if ((tg == BJV || tg == BJ0 || tg == BJ1 || tg == BJM) && vl > base) { HEAP[loc] = term_new(0, tg, term_ext(t), vl + n); return; } diff --git a/clang/parse/include.c b/clang/parse/include.c index 18d3d0f..c90b7c1 100644 --- a/clang/parse/include.c +++ b/clang/parse/include.c @@ -26,7 +26,11 @@ fn void parse_include(PState *s) { if (PARSE_SEEN_FILES_LEN >= 1024) { sys_error("MAX_INCLUDES"); } - PARSE_SEEN_FILES[PARSE_SEEN_FILES_LEN++] = strdup(path); + char *path_copy = strdup(path); + if (!path_copy) { + sys_error("out of memory in parse_include"); + } + PARSE_SEEN_FILES[PARSE_SEEN_FILES_LEN++] = path_copy; // Read and parse char *src = sys_file_read(path); diff --git a/clang/parse/term/str.c b/clang/parse/term/str.c index 3151f4a..911f395 100644 --- a/clang/parse/term/str.c +++ b/clang/parse/term/str.c @@ -13,6 +13,9 @@ fn Term parse_term_str(PState *s, u32 depth) { } else { c = parse_utf8(s); } + if (n >= 4096) { + parse_error(s, "string too long (max 4096 codepoints)", '"'); + } cs[n++] = c; } parse_advance(s); diff --git a/clang/table/find.c b/clang/table/find.c index 9867fbc..a68c5e4 100644 --- a/clang/table/find.c +++ b/clang/table/find.c @@ -11,6 +11,9 @@ fn u32 table_find(const char *name, u32 len) { // Not found - create new entry u32 id = TABLE_LEN++; char *copy = malloc(len + 1); + if (!copy) { + sys_error("out of memory in table_find"); + } memcpy(copy, name, len); copy[len] = '\0'; TABLE[id] = copy;