summaryrefslogtreecommitdiff
path: root/internal.h
diff options
context:
space:
mode:
author卜部昌平 <[email protected]>2019-10-07 16:56:08 +0900
committer卜部昌平 <[email protected]>2019-10-09 12:12:28 +0900
commit7e0ae1698d4db0baec858a46de8d1ae875360cf5 ()
tree646fbe720b13469679973060b8ab5299cf076236 /internal.h
parenta220410be70264a0e4089c4d63a9c22dd688ca7c (diff)
avoid overflow in integer multiplication
This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes.
Notes: Merged: https://.com/ruby/ruby/pull/2540
-rw-r--r--internal.h9
1 files changed, 8 insertions, 1 deletions
@@ -1627,7 +1627,7 @@ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR
void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_ALLOC_SIZE((2, 3));
void ruby_sized_xfree(void *x, size_t size);
RUBY_SYMBOL_EXPORT_END
-#define SIZED_REALLOC_N(var,type,n,old_n) ((var)=(type*)ruby_sized_xrealloc((char*)(var), (n) * sizeof(type), (old_n) * sizeof(type)))
#endif
/* optimized version of NEWOBJ() */
@@ -1647,6 +1647,13 @@ __attribute__((__alloc_align__(1)))
void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((2));
void rb_aligned_free(void *);
/* hash.c */
#if RHASH_CONVERT_TABLE_DEBUG
struct st_table *rb_hash_tbl_raw(VALUE hash, const char *file, int line);