Skip to content

chore: compiler memory safety, perf, and CodeQL cleanup#1610

Merged
SchoolyB merged 15 commits intomainfrom
chore/code-quality
May 5, 2026
Merged

chore: compiler memory safety, perf, and CodeQL cleanup#1610
SchoolyB merged 15 commits intomainfrom
chore/code-quality

Conversation

@SchoolyB
Copy link
Copy Markdown
Owner

@SchoolyB SchoolyB commented May 5, 2026

  • Free four leaked malloc'd buffers in codegen module/func-ref resolution (ns_name, mangled, rn, check_name/prefix)
  • New util/xalloc.h (xmalloc/xcalloc/xrealloc) — abort-on-OOM helpers matching the inline pattern already in buf.c/arena.c
  • Routed all unchecked malloc/calloc/realloc calls in codegen.c, typechecker.c, types.c, scope.c, error.c through the xalloc helpers
  • Removed dead "skip on OOM" branches in typechecker that were silently producing incomplete state on allocation failure

Performance

  • error_codes.c: chained strcmp lookup → sorted bsearch

  • typechecker/types.c::type_from_name: ~25 chained strcmps → static sorted bsearch table dispatching singletons + sized variants in one shot

  • codegen.c: replaced O(struct_count × field_count) scan in the member-call fallback heuristic with a lazily-built (field_name, struct_name) index over only func-typed fields

  • codegen.c::find_func: linear scan → separate sorted view (funcs_by_name) + bsearch. cg->all_funcs keeps insertion order so emission and prefix-match scans

  • stream arg in non-container char print (emitf had 2 %s and 3 args)

  • heap-allocated mangled buffer in monomorphisation forward-decl loop instead of letting a stack address briefly live in the AST

  • replaced two duplicated case-insensitive true/false parsers with strncasecmp
    -io.copy_file now creates the destination with mode 0644 via open()+fdopen() instead of fopen()'s 0666-mod-umask default
    ez_arrays.remove_float needs bit-equal lookup; fmt_shortest_float is the canonical round-trip-precision idiom

@github-actions github-actions Bot added typechecker Related to type checking and validation stdlib General standard library issues ezc EZC compiler tool (EZ → C → native binary) labels May 5, 2026
size_t klen = (size_t)(colon - start);
char *key = malloc(klen + 1);
if (!key) return &TYPE_UNKNOWN;
char *key = xmalloc(klen + 1);
@SchoolyB SchoolyB merged commit 16f0b8a into main May 5, 2026
6 checks passed
@SchoolyB SchoolyB deleted the chore/code-quality branch May 5, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ezc EZC compiler tool (EZ → C → native binary) stdlib General standard library issues typechecker Related to type checking and validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants