From 7850d29ad5cb3883d7eaddf91e7812ba0553c99f Mon Sep 17 00:00:00 2001 From: say Date: Tue, 12 May 2026 10:36:55 -0700 Subject: [PATCH] fix: correct allocation size for Range struct in prime factorization malloc(sizeof(range)) allocated only pointer size instead of the full struct, causing a heap-buffer-overflow when writing pstr->length. Use sizeof(*pstr) so the whole struct is allocated. Fixes #1568. --- 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..cf346b50be 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(*pstr)); assert(pstr); while (n % 2 == 0)