From 6bd313ee07c498bf83c9ea7cb9305f71676fdfad Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 30 Sep 2026 14:44:14 +0100 Subject: [PATCH] Array.fill stops before `end` fill's loop ran `i <= end`, so it filled one element past the range, and with the default `end = this.length` it wrote one element past the end of the array it had just copied: a heap overrun, usually hidden by the allocator rounding the block up, and the likely cause of array_fill's intermittent 0xC0000374 under -mm=rc. A guard-page heap catches the write every run. It now runs `i < end`. array_fill.ts now asserts its results and adds `[1, 2, 3].fill(9, 1, 2)`, which gave [1, 9, 9] before. Co-Authored-By: Claude Opus 5.5 --- src/generics/lib.generics.ts | 2 +- tests/array_fill.ts | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/generics/lib.generics.ts b/src/generics/lib.generics.ts index 4376a2d..f59534c 100644 --- a/src/generics/lib.generics.ts +++ b/src/generics/lib.generics.ts @@ -141,7 +141,7 @@ namespace __Array { end = this.length; } - for (let i = start; i <= end; i++) + for (let i = start; i < end; i++) newArray[i] = value; return newArray; diff --git a/tests/array_fill.ts b/tests/array_fill.ts index 4d9986d..bdef201 100644 --- a/tests/array_fill.ts +++ b/tests/array_fill.ts @@ -2,14 +2,27 @@ function main() { const array1 = [1, 2, 3, 4]; // Fill with 0 from position 2 until position 4 - console.log(array1.fill(0, 2, 4)); + const zeros = array1.fill(0, 2, 4); + console.log(zeros); // Expected output: Array [1, 2, 0, 0] + assert(zeros.length == 4 && zeros[0] == 1 && zeros[1] == 2 && zeros[2] == 0 && zeros[3] == 0); // Fill with 5 from position 1 - console.log(array1.fill(5, 1)); + const fives = array1.fill(5, 1); + console.log(fives); // Expected output: Array [1, 5, 5, 5] + assert(fives.length == 4 && fives[0] == 1 && fives[1] == 5 && fives[2] == 5 && fives[3] == 5); - console.log(array1.fill(6)); + const sixes = array1.fill(6); + console.log(sixes); // Expected output: Array [6, 6, 6, 6] + assert(sixes.length == 4 && sixes[0] == 6 && sixes[1] == 6 && sixes[2] == 6 && sixes[3] == 6); + + // `end` is not filled: this wrote one past it, and past the end of the array when `end` is its length + const inner = [1, 2, 3].fill(9, 1, 2); + console.log(inner); + // Expected output: Array [1, 9, 3] + assert(inner.length == 3 && inner[0] == 1 && inner[1] == 9 && inner[2] == 3); + console.log("ALL DONE"); }