Commit cb1a53cc

cb1a53ccb854Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified

Description

fix: address Gemini review high-priority issues from PRs #193/#194/#195

  • Range#map: when receiver is a non-literal range (e.g. r = 1..3; r.map {...}), don't read @nd_left/@nd_right on a non-RangeNode (LocalVariableReadNode etc) — fall back to the runtime sp_Range's .first/.last fields. Bug produced wrong output (3 vs 1 in the reduced repro). [PR #193 high]

  • sp_file_binread_bytes: drive the push loop by fread's actual byte count (not ftell's raw size) to avoid pushing uninitialized memory on a partial read; null-check the malloc result before use. [PR #194 high]

  • compile_array_literal SplatNode branch:

    • SP_GC_ROOT the accumulator (sp_IntArray_push can grow → trigger GC, sweeping the half-built array).
    • Hoist the range upper bound and the source-array expr to a temp so side effects don't re-fire each iteration.
    • Add sym_array support (shares sp_IntArray representation with int_array). [PR #195 high]

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
cb1a53ccb854
Parent
c73573c268b2

lib/sp_runtime.hmodifiedView file

@@ -852,10 +852,11 @@
852852 long sz = ftell(f);
853853 fseek(f, 0, SEEK_SET);
854854 unsigned char *buf = (unsigned char *)malloc(sz > 0 ? (size_t)sz : 1);
855- if (sz > 0) {
856- size_t r = fread(buf, 1, sz, f);
857- (void)r;
858- for (long i = 0; i < sz; i++) sp_IntArray_push(a, (mrb_int)buf[i]);
855+ if (buf && sz > 0) {
856+ /* Use fread's actual byte count, not the raw file size — a
857+ partial read otherwise pushes uninitialized memory. */
858+ size_t r = fread(buf, 1, (size_t)sz, f);
859+ for (size_t i = 0; i < r; i++) sp_IntArray_push(a, (mrb_int)buf[i]);
859860 }
860861 free(buf);
861862 fclose(f);