* lib/resolv.rb (Resolv::DNS::Message::MessageDecoder#get_labels):

Make it iterative.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-02-08 07:35:24 +00:00
Родитель c6f2c9383f
Коммит f01b5e217b
2 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Sat Feb 8 16:34:36 2014 Tanaka Akira <akr@fsij.org>
* lib/resolv.rb (Resolv::DNS::Message::MessageDecoder#get_labels):
Make it iterative.
Sat Feb 8 15:54:12 2014 Koichi Sasada <ko1@atdot.net>
* gc.c, gc.h (rb_objspace_marked_object_p): added.

Просмотреть файл

@ -1572,30 +1572,33 @@ class Resolv
return Name.new(self.get_labels)
end
def get_labels(limit=nil)
limit = @index if !limit || @index < limit
def get_labels
prev_index = @index
save_index = nil
d = []
while true
raise DecodeError.new("limit exceeded") if @limit <= @index
case @data[@index].ord
when 0
@index += 1
if save_index
@index = save_index
end
return d
when 192..255
idx = self.get_unpack('n')[0] & 0x3fff
if limit <= idx
if prev_index <= idx
raise DecodeError.new("non-backward name pointer")
end
save_index = @index
prev_index = idx
if !save_index
save_index = @index
end
@index = idx
d += self.get_labels(limit)
@index = save_index
return d
else
d << self.get_label
end
end
return d
end
def get_label