Skip to content

Commit

Permalink
Merge pull request #64 from ksss/segv
Browse files Browse the repository at this point in the history
Fix segmentation fault
  • Loading branch information
mattn committed Mar 24, 2017
2 parents 071fc4e + 712c264 commit be2ed0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mruby_onig_regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,8 @@ string_split(mrb_state* mrb, mrb_value self) {
}

if(mrb_data_check_get_ptr(mrb, pattern, &mrb_onig_regexp_type) == NULL) {
if (!mrb_nil_p(pattern) && RSTRING_LEN(pattern) == 0) {
if(!mrb_nil_p(pattern)) { pattern = mrb_string_type(mrb, pattern); }
if(mrb_string_p(pattern) && RSTRING_LEN(pattern) == 0) {
char* p = RSTRING_PTR(self);
char* e = p + RSTRING_LEN(self);
int n = 0;
Expand Down
7 changes: 7 additions & 0 deletions test/mruby_onig_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ def onig_match_data_example
assert_equal ['1', '', '2', '3', '', '4', '', ''], test_str.onig_regexp_split(OnigRegexp.new(','), -4)

assert_equal [], ''.onig_regexp_split(OnigRegexp.new(','), -1)

o = Object.new
def o.to_str
","
end
assert_equal ["こ", "に", "ち", "わ"], "こ,に,ち,わ".onig_regexp_split(o)
assert_raise(TypeError) { "".onig_regexp_split(1) }
end

assert('String#index') do
Expand Down

0 comments on commit be2ed0d

Please sign in to comment.