Permalink
Browse files

Save/restore GC arena index to avoid arena overflow error.

  • Loading branch information...
matz committed Mar 18, 2017
1 parent 00427d4 commit 6ea26aafd5a2d64987bd1607f9212f6ce494765c
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/error.c
View
@@ -329,6 +329,7 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap)
const char *b = p;
ptrdiff_t size;
mrb_value ary = mrb_ary_new_capa(mrb, 4);
int ai = mrb_gc_arena_save(mrb);
while (*p) {
const char c = *p++;
@@ -352,14 +353,18 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap)
break;
}
}
mrb_gc_arena_restore(mrb, ai);
}
if (b == format) {
return mrb_str_new_cstr(mrb, format);
}
else {
size = p - b;
mrb_ary_push(mrb, ary, mrb_str_new(mrb, b, size));
return mrb_ary_join(mrb, ary, mrb_str_new(mrb, NULL, 0));
if (size > 0) {
mrb_ary_push(mrb, ary, mrb_str_new(mrb, b, size));
mrb_gc_arena_restore(mrb, ai);
}
return mrb_ary_join(mrb, ary, mrb_nil_value());
}
}

0 comments on commit 6ea26aa

Please sign in to comment.