Permalink
Browse files

Fix segfault when Fixnum#chr doesn't return a string

  • Loading branch information...
bouk committed Nov 23, 2016
1 parent 669bbc7 commit 9bf1c0e1dc09d9aa577554d58d91f3889a77b918
Showing with 24 additions and 0 deletions.
  1. +1 −0 mrbgems/mruby-sprintf/src/sprintf.c
  2. +23 −0 mrbgems/mruby-sprintf/test/sprintf.rb
@@ -675,6 +675,7 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
else {
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid character");
}
mrb_check_type(mrb, tmp, MRB_TT_STRING);
c = RSTRING_PTR(tmp);
n = RSTRING_LEN(tmp);
if (!(flags & FWIDTH)) {
@@ -7,3 +7,26 @@
assert_equal "123 < 456", "%{num} < %<str>s" % { num: 123, str: "456" }
assert_equal 15, ("%b" % (1<<14)).size
end
assert("String#% with invalid chr") do
begin
class Fixnum
alias_method :chr_, :chr if method_defined?(:chr)
def chr
nil
end
end
assert_raise TypeError do
"%c" % 0
end
ensure
class Fixnum
if method_defined?(:chr_)
alias_method :chr, :chr_
remove_method :chr_
end
end
end
end

0 comments on commit 9bf1c0e

Please sign in to comment.