Use size_t to calculate bytes needed for array.

parent 246a9a8a
...@@ -20,15 +20,12 @@ static struct RArray* ...@@ -20,15 +20,12 @@ static struct RArray*
ary_new_capa(mrb_state *mrb, mrb_int capa) ary_new_capa(mrb_state *mrb, mrb_int capa)
{ {
struct RArray *a; struct RArray *a;
mrb_int blen; size_t blen;
if (capa > ARY_MAX_SIZE) { if (capa > ARY_MAX_SIZE) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big"); mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
} }
blen = capa * sizeof(mrb_value); blen = capa * sizeof(mrb_value);
if (blen < capa) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
}
a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class); a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class);
a->ptr = (mrb_value *)mrb_malloc(mrb, blen); a->ptr = (mrb_value *)mrb_malloc(mrb, blen);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment