summaryrefslogtreecommitdiffhomepage
path: root/src/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/array.c')
-rw-r--r--src/array.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/array.c b/src/array.c
index 855a45aba..75b2cd0c1 100644
--- a/src/array.c
+++ b/src/array.c
@@ -2,7 +2,6 @@
#include "mruby/array.h"
#include <string.h>
#include "mruby/string.h"
-#include "mdata.h"
#include "mruby/class.h"
#ifdef INCLUDE_REGEXP
@@ -35,10 +34,8 @@ mrb_value
mrb_ary_new_capa(mrb_state *mrb, size_t capa)
{
struct RArray *a;
+ size_t blen;
- if (capa < 0) {
- mrb_raise(mrb, E_ARGUMENT_ERROR, "negative ary size (or size too big)");
- }
#ifdef LONG_MAX
if (capa > ARY_MAX_SIZE) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big");
@@ -47,10 +44,14 @@ mrb_ary_new_capa(mrb_state *mrb, size_t capa)
if (capa < ARY_DEFAULT_LEN) {
capa = ARY_DEFAULT_LEN;
}
+ blen = capa * sizeof(mrb_value) ;
+ if (blen < capa) {
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big");
+ }
a = mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class);
- a->buf = mrb_malloc(mrb, sizeof(mrb_value) * capa);
- memset(a->buf, 0, sizeof(mrb_value) * capa);
+ a->buf = mrb_malloc(mrb, blen);
+ memset(a->buf, 0, blen);
a->capa = capa;
a->len = 0;