Commit 6b6c590f authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1722 from take-cheeze/hash_ext_arena_fix

Fix possible arena overflow in mruby-hast-ext.
parents 96e806ff 658b4f4e
......@@ -23,12 +23,14 @@ static mrb_value
hash_values_at(mrb_state *mrb, mrb_value hash)
{
mrb_value *argv, result;
int argc, i;
int argc, i, ai;
mrb_get_args(mrb, "*", &argv, &argc);
result = mrb_ary_new_capa(mrb, argc);
ai = mrb_gc_arena_save(mrb);
for (i = 0; i < argc; i++) {
mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i]));
mrb_gc_arena_restore(mrb, ai);
}
return result;
}
......
......@@ -21,4 +21,9 @@ end
assert('Hash#values_at') do
h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
assert_equal ["bovine", "feline"], h.values_at("cow", "cat")
keys = []
(0...1000).each { |v| keys.push "#{v}" }
h = Hash.new { |hash,k| hash[k] = k }
assert_equal keys, h.values_at(*keys)
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment