From 2e3b2d5eb25aff54bc97b93743b3e517096ca221 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 24 Dec 2024 17:50:51 -0500 Subject: [PATCH] Change rb_darray_calloc_mul_add_without_gc to check for overflow --- darray.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/darray.h b/darray.h index e492d6a34f..8524cd645e 100644 --- a/darray.h +++ b/darray.h @@ -163,12 +163,11 @@ rb_darray_free_without_gc(void *ary) free(ary); } -/* Internal function. Like rb_xcalloc_mul_add but does not trigger GC and does - * not check for overflow in arithmetic. */ +/* Internal function. Like rb_xcalloc_mul_add but does not trigger GC. */ static inline void * rb_darray_calloc_mul_add_without_gc(size_t x, size_t y, size_t z) { - size_t size = (x * y) + z; + size_t size = rbimpl_size_add_or_raise(rbimpl_size_mul_or_raise(x, y), z); void *ptr = calloc(1, size); if (ptr == NULL) rb_bug("rb_darray_calloc_mul_add_without_gc: failed");