aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-11 06:22:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-11 06:22:34 +0000
commit471e3a301624a86f08c86a643321c3656abbc9fd (patch)
treefeb1199979bf7b7ad2e54a4e3898a66420103e4a /gc.c
parent0a8a321558e94c96ed03bbab1bd2048a81f52eb1 (diff)
downloadruby-471e3a301624a86f08c86a643321c3656abbc9fd.tar.gz
ruby.h: check integer overflow
* include/ruby/ruby.h (ALLOCV_N): check integer overflow, as well as ruby_xmalloc2. pointed out by Paul <pawlkt AT gmail.com>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/gc.c b/gc.c
index a3af6fefbb..cd8682547a 100644
--- a/gc.c
+++ b/gc.c
@@ -7649,16 +7649,16 @@ ruby_xmalloc(size_t size)
return objspace_xmalloc(&rb_objspace, size);
}
-static inline size_t
-xmalloc2_size(size_t n, size_t size)
+void
+ruby_malloc_size_overflow(size_t count, size_t elsize)
{
- size_t len = size * n;
- if (n != 0 && size != len / n) {
- rb_raise(rb_eArgError, "malloc: possible integer overflow");
- }
- return len;
+ rb_raise(rb_eArgError,
+ "malloc: possible integer overflow (%"PRIdSIZE"*%"PRIdSIZE")",
+ count, elsize);
}
+#define xmalloc2_size ruby_xmalloc2_size
+
void *
ruby_xmalloc2(size_t n, size_t size)
{