Change rb_darray_calloc_mul_add_without_gc to check for overflow

This commit is contained in:
Peter Zhu 2024-12-24 17:50:51 -05:00
parent 99ff0224a5
commit 2e3b2d5eb2
Notes: git 2025-01-02 16:03:25 +00:00

View File

@ -163,12 +163,11 @@ rb_darray_free_without_gc(void *ary)
free(ary); free(ary);
} }
/* Internal function. Like rb_xcalloc_mul_add but does not trigger GC and does /* Internal function. Like rb_xcalloc_mul_add but does not trigger GC. */
* not check for overflow in arithmetic. */
static inline void * static inline void *
rb_darray_calloc_mul_add_without_gc(size_t x, size_t y, size_t z) 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); void *ptr = calloc(1, size);
if (ptr == NULL) rb_bug("rb_darray_calloc_mul_add_without_gc: failed"); if (ptr == NULL) rb_bug("rb_darray_calloc_mul_add_without_gc: failed");