Skip to content
Permalink
Browse files

Merge pull request #851 from kachick/guard-uninitialized-regexp

Guard uninitialized Regexp#match from segfault
  • Loading branch information
alex committed Oct 18, 2015
2 parents f23a33e + 7ac60ba commit d3991e0674afb2667c6a29d679d6a9d49f80003a
Showing with 8 additions and 0 deletions.
  1. +6 −0 tests/objects/test_regexpobject.py
  2. +2 −0 topaz/objects/regexpobject.py
@@ -140,6 +140,12 @@ def test_new_regexp(self, space):
w_res = space.execute("return Regexp.new(/abc/).source")
assert space.str_w(w_res) == "abc"

def test_allocate(self, space):
with self.raises(space, "TypeError", "uninitialized Regexp"):
space.execute("Regexp.allocate.source")
with self.raises(space, "TypeError", "uninitialized Regexp"):
space.execute("Regexp.allocate.match ''")

def test_size(self, space):
w_res = space.execute("""
/(a)(b)(c)/ =~ "hey hey, abc, hey hey"
@@ -51,6 +51,7 @@ class W_RegexpObject(W_Object):

def __init__(self, space, source, flags):
W_Object.__init__(self, space)
self.source = None
self.set_source(space, source, flags)

@classdef.setup_class
@@ -219,6 +220,7 @@ def method_match_operator(self, space, w_s):

@classdef.method("match")
def method_match(self, space, w_s, w_offset=None):
self._check_initialized(space)
if w_s is space.w_nil:
return space.w_nil
s = Coerce.str(space, w_s)

0 comments on commit d3991e0

Please sign in to comment.