diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-03-18 17:37:24 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-03-18 17:37:24 +0900 |
| commit | 6ea26aafd5a2d64987bd1607f9212f6ce494765c (patch) | |
| tree | 53bc5669f4d9916455d3c67dcd49f76e68784d7e /src/error.c | |
| parent | 00427d45f508bb211f05383472f6963eaf0a284a (diff) | |
| download | mruby-6ea26aafd5a2d64987bd1607f9212f6ce494765c.tar.gz mruby-6ea26aafd5a2d64987bd1607f9212f6ce494765c.zip | |
Save/restore GC arena index to avoid arena overflow error.
Diffstat (limited to 'src/error.c')
| -rw-r--r-- | src/error.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/error.c b/src/error.c index 01c0e376c..6d488372e 100644 --- a/src/error.c +++ b/src/error.c @@ -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()); } } |
