From 10a58878d7bed8d2975747221f676fbb2b702be9 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 25 Mar 2024 15:32:07 +0200 Subject: [PATCH] fix GroupLen on array elements outside i64 range --- src/builtins/sysfn.c | 12 +++++++++--- test/cases/prims.bqn | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index acbbf478..81c3c6a5 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -152,12 +152,18 @@ B fill_c2(B t, B w, B x) { // TODO not set fill for typed arrays B grLen_both(i64 ria, B x) { usz ia = IA(x); + if (ia==0) return taga(arr_shVec(allZeroes(ria<=0? 0 : ria))); SGetU(x) + f64 xmaxf = -1; for (usz i = 0; i < ia; i++) { - i64 c = o2i64G(GetU(x, i)); - if (c>ria) ria = c; + f64 c = o2fG(GetU(x, i)); + if (c>xmaxf) xmaxf = c; + } + if (xmaxf >= USZ_MAX) thrOOM(); + if ((i64)xmaxf > ria) { + ria = (i64)xmaxf; + if (ria >= (i64)USZ_MAX) thrOOM(); } - if (ria > (i64)(USZ_MAX-1)) thrOOM(); ria++; B r; { diff --git a/test/cases/prims.bqn b/test/cases/prims.bqn index 86a1f90e..61575e97 100644 --- a/test/cases/prims.bqn +++ b/test/cases/prims.bqn @@ -248,6 +248,8 @@ w←1‿1⥊1 ⋄ x←2⥊1 ⋄ w‿x <¨↩ ⋄ {! (∾⟨•Repr𝕩,": Expe # ⊔ !"⊔: ≠𝕨 must be either ≠𝕩 or one bigger (2≡≠𝕨, 3≡≠𝕩)" % 0‿0⊔↕3 +!"Out of memory" % ⟨∞⟩⊔"a" +!"Out of memory" % ⟨1e50⟩⊔"a" # ↕𝕩 !"Expected non-negative integer, got character" % ↕@