Permalink
Browse files

ary_expand_capa(): refine conditions to avoid infinite loop; ref #3353

  • Loading branch information...
matz committed Dec 31, 2016
1 parent 9d84f0d commit cfdd1e3cc6ec9ac7ba81ec6fad5d5ba4d11334b9
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/array.c
View
@@ -170,20 +170,23 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, size_t len)
size_t capa = a->aux.capa;
if (len > ARY_MAX_SIZE) {
size_error:
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
}
if (capa == 0) {
capa = ARY_DEFAULT_LEN;
}
while (capa < len) {
capa *= 2;
if (capa > ARY_MAX_SIZE) {
capa = ARY_MAX_SIZE;
if (capa <= ARY_MAX_SIZE / 2) {
capa *= 2;
}
else {
goto size_error;
}
}
if (capa < len || capa > MRB_INT_MAX) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
goto size_error;
}
if (capa > (size_t)a->aux.capa) {

0 comments on commit cfdd1e3

Please sign in to comment.