Skip to content

Commit

Permalink
ObjectSpace._id2ref raises for invalid ID values
Browse files Browse the repository at this point in the history
Fixes #3504
  • Loading branch information
Yorick Peterse committed Feb 12, 2016
1 parent 8b7d91b commit 89cf641
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/object_space.rb
Expand Up @@ -6,11 +6,12 @@ def self.find_object(query, callable)

def self._id2ref(id)
ary = []

if find_object([:object_id, Integer(id)], ary) > 0
return ary.first
end

return nil
raise RangeError, "#{id} is not a valid ID value"
end

def self.find_references(obj)
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/objectspace/_id2ref_spec.rb
Expand Up @@ -18,4 +18,8 @@
r = ObjectSpace._id2ref(s.object_id)
r.should == s
end

it 'raises RangeError when an object could not be found' do
proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
end
end

0 comments on commit 89cf641

Please sign in to comment.