diff options
Diffstat (limited to 'mrbgems/mruby-string-ext/src/string.c')
| -rw-r--r-- | mrbgems/mruby-string-ext/src/string.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c index 7bb6254ce..6718e734a 100644 --- a/mrbgems/mruby-string-ext/src/string.c +++ b/mrbgems/mruby-string-ext/src/string.c @@ -112,16 +112,19 @@ mrb_str_concat2(mrb_state *mrb, mrb_value self) static mrb_value mrb_str_start_with(mrb_state *mrb, mrb_value self) { - mrb_value *argv; + mrb_value *argv, sub; int argc, i; mrb_get_args(mrb, "*", &argv, &argc); for (i = 0; i < argc; i++) { size_t len_l, len_r; + int ai = mrb_gc_arena_save(mrb); + sub = mrb_string_type(mrb, argv[i]); + mrb_gc_arena_restore(mrb, ai); len_l = RSTRING_LEN(self); - len_r = RSTRING_LEN(argv[i]); + len_r = RSTRING_LEN(sub); if (len_l >= len_r) { - if (memcmp(RSTRING_PTR(self), RSTRING_PTR(argv[i]), len_r) == 0) { + if (memcmp(RSTRING_PTR(self), RSTRING_PTR(sub), len_r) == 0) { return mrb_true_value(); } } @@ -138,17 +141,20 @@ mrb_str_start_with(mrb_state *mrb, mrb_value self) static mrb_value mrb_str_end_with(mrb_state *mrb, mrb_value self) { - mrb_value *argv; + mrb_value *argv, sub; int argc, i; mrb_get_args(mrb, "*", &argv, &argc); for (i = 0; i < argc; i++) { size_t len_l, len_r; + int ai = mrb_gc_arena_save(mrb); + sub = mrb_string_type(mrb, argv[i]); + mrb_gc_arena_restore(mrb, ai); len_l = RSTRING_LEN(self); - len_r = RSTRING_LEN(argv[i]); + len_r = RSTRING_LEN(sub); if (len_l >= len_r) { if (memcmp(RSTRING_PTR(self) + (len_l - len_r), - RSTRING_PTR(argv[i]), + RSTRING_PTR(sub), len_r) == 0) { return mrb_true_value(); } |
