summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 11:42:31 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 11:42:31 +0000
commitfac42e6c766a32734b055d0bfccb09ded14783d9 (patch)
treec3cb4b56a02671ecd184b2b23c38927c3e50b6e9 /gc.c
parent5fd589287db669fdfe672ba563d16bb265652fac (diff)
* include/ruby/ruby.h (rb_mul_size_overflow): added to handle
mul overflow efficiently. * include/ruby/ruby.h (rb_alloc_tmp_buffer2): use rb_mul_size_overflow and avoid division where it can define DSIZE_T. * gc.c (xmalloc2_size): moved from ruby.h and use rb_mul_size_overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/gc.c b/gc.c
index aa6770123c..d9f495ba29 100644
--- a/gc.c
+++ b/gc.c
@@ -7792,7 +7792,16 @@ objspace_xmalloc(rb_objspace_t *objspace, size_t size)
return objspace_xmalloc0(objspace, size);
}
-#define xmalloc2_size ruby_xmalloc2_size
+static inline size_t
+xmalloc2_size(const size_t count, const size_t elsize)
+{
+ size_t ret;
+ if (rb_mul_size_overflow(count, elsize, SSIZE_MAX, &ret)) {
+ ruby_malloc_size_overflow(count, elsize);
+ }
+ return ret;
+}
+
static void *
objspace_xmalloc2(rb_objspace_t *objspace, size_t n, size_t size)
{