From 4c32971b3235a4406a6362ea454586a64a15e9a4 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Mon, 11 May 2026 19:14:49 -0700 Subject: [PATCH] fix: allocate struct size in prime_factoriziation int_fact Inside int_fact, the local 'int *range' shadows the 'range' typedef, so malloc(sizeof(range)) reserves only sizeof(int*) bytes. Writing pstr->length one line later overflows the heap allocation. Reproduces under AddressSanitizer. Allocate sizeof(struct data) instead, which the issue author suggested as a working fix. Closes #1568 Signed-off-by: SAY-5 --- math/prime_factoriziation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/prime_factoriziation.c b/math/prime_factoriziation.c index 7e466923be..51ff35a1a9 100644 --- a/math/prime_factoriziation.c +++ b/math/prime_factoriziation.c @@ -66,7 +66,7 @@ Range int_fact(int n) int i = 0; int *range = (int *)malloc(sizeof(int) * len); assert(range); - Range pstr = (Range)malloc(sizeof(range)); + Range pstr = (Range)malloc(sizeof(struct data)); assert(pstr); while (n % 2 == 0)