summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-string-ext/src/string.c')
-rw-r--r--mrbgems/mruby-string-ext/src/string.c18
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 edebcecbc..4bb9b9621 100644
--- a/mrbgems/mruby-string-ext/src/string.c
+++ b/mrbgems/mruby-string-ext/src/string.c
@@ -111,16 +111,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, len_cmp;
+ 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);
len_cmp = (len_l > len_r) ? len_r : len_l;
- if (memcmp(RSTRING_PTR(self), RSTRING_PTR(argv[i]), len_cmp) == 0) {
+ if (memcmp(RSTRING_PTR(self), RSTRING_PTR(sub), len_cmp) == 0) {
return mrb_true_value();
}
}
@@ -136,17 +139,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, len_cmp;
+ 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);
len_cmp = (len_l > len_r) ? len_r : len_l;
if (memcmp(RSTRING_PTR(self) + (len_l - len_cmp),
- RSTRING_PTR(argv[i]) + (len_r - len_cmp),
+ RSTRING_PTR(sub) + (len_r - len_cmp),
len_cmp) == 0) {
return mrb_true_value();
}