From 09936204d01845231b45eecce6a991436a9530bf Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 28 May 2025 02:43:21 +0300 Subject: [PATCH] fix withFill being passed object with incomplete shape caught by fuzz.bqn --- src/builtins/sfns.c | 9 ++++----- src/utils/mut.c | 18 ++++++++++++++++++ src/utils/mut.h | 3 +++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index b32f9a00..47672826 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -101,12 +101,11 @@ static Arr* take_head(usz ria, B x) { // consumes; returns ria↑x with unset sh try_copy:; // if (used > 64) goto base; - MAKE_MUT_INIT(rm, ria, TI(x,elType)); MUTG_INIT(rm); - mut_copyG(rm, 0, x, 0, ria); - Arr* r = mut_fp(rm); - if (xt==t_fillarr) r = a(withFill(taga(arr_shVec(r)), getFillR(x))); + UntaggedArr r = m_arrp_fill(x, ria); + COPY_TO(r.data, TI(x,elType), 0, x, 0, ria); + NOGC_E; decG(x); - return r; + return r.obj; } base:; return TI(x,slice)(x,0,ria); diff --git a/src/utils/mut.c b/src/utils/mut.c index 41b908d2..a459dc08 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -832,6 +832,24 @@ DirectArr toEltypeArr(B x, u8 re) { // consumes +UntaggedArr m_arrp_fill(B x, ux ia) { // doesn't consume + u8 xe = TI(x,elType); + if (xe==el_B) { + B fill = getFillR(x); + if (noFill(fill)) { + Arr* r = m_fillarrp(ia); + fillarr_setFill(r, fill); + return (UntaggedArr){r, fillarrv_ptr(r)}; + } else { + HArr_p r = m_harrUp(ia); + return (UntaggedArr) {(Arr*)r.c, r.a}; + } + } + Arr* r; + void* rp = m_tyarrlbp(&r, elwBitLog(xe), ia, el2t(xe)); + return (UntaggedArr) {r, rp}; +} + static NOINLINE DirectArr m_fillarrAs(B x, B fill) { // doesn't consume Arr* r = arr_shCopy(m_fillarrp(IA(x)), x); fillarr_setFill(r, fill); diff --git a/src/utils/mut.h b/src/utils/mut.h index affaec01..7ff4b7da 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -297,6 +297,9 @@ DirectArr toEltypeArr(B x, u8 re); // consumes // Otherwise, functionality is the same as if a regular new array was made (i.e. uninitialized elements, may start NOGC) DirectArr potentiallyReuse(B x); // doesn't consume +typedef struct { Arr* obj; void* data; } UntaggedArr; +UntaggedArr m_arrp_fill(B x, ux ia); // doesn't consume; create new array with the fill and eltype of x + typedef struct { B res; void* rp;