Skip to content

Commit

Permalink
* range.c (rb_range_beg_len): returns Qnil only when "beg" points
Browse files Browse the repository at this point in the history
  outside of a range.  No boundary check for "end".


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Jul 24, 2004
1 parent d1f820b commit 42f0ec9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Sat Jul 24 13:32:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>

* range.c (rb_range_beg_len): returns Qnil only when "beg" points
outside of a range. No boundary check for "end".

Fri Jul 23 16:40:25 2004 Yukihiro Matsumoto <matz@ruby-lang.org>

* gc.c (define_final): should not disclose NODE* to Ruby world.
Expand Down
6 changes: 2 additions & 4 deletions array.c
Expand Up @@ -620,10 +620,8 @@ rb_ary_subseq(ary, beg, len)
* continuing for _length_ elements, or returns a subarray
* specified by _range_.
* Negative indices count backward from the end of the
* array (-1 is the last element). Returns nil if any indices
* are out of range unless the index equals the array size and a
* _length_ or _range_ parameter is given, in which case an
* empty array is returned.
* array (-1 is the last element). Returns nil if the index
* (or starting index) are out of range.
*
* a = [ "a", "b", "c", "d", "e" ]
* a[2] + a[0] + a[1] #=> "cab"
Expand Down
2 changes: 1 addition & 1 deletion lib/ping.rb
Expand Up @@ -49,7 +49,7 @@ def pingecho(host, timeout=5, service="echo")
end
rescue Errno::ECONNREFUSED
return true
rescue
rescue Timeout::Error
return false
end
return true
Expand Down
6 changes: 2 additions & 4 deletions range.c
Expand Up @@ -480,14 +480,12 @@ rb_range_beg_len(range, begp, lenp, len, err)
}
if (err == 0 || err == 2) {
if (beg > len) goto out_of_range;
if (end > len)
end = len;
if (end > len) end = len;
}
if (end < 0) end += len;
if (!EXCL(range)) end++; /* include end point */
if (end < 0) goto out_of_range;
len = end - beg;
if (len < 0) goto out_of_range;
if (len < 0) len = 0;

*begp = beg;
*lenp = len;
Expand Down
3 changes: 2 additions & 1 deletion string.c
Expand Up @@ -1543,7 +1543,8 @@ rb_str_aref(str, indx)
* a[1..3] #=> "ell"
* a[-3,2] #=> "er"
* a[-4..-2] #=> "her"
* a[-2..-4] #=> nil
* a[12..-1] #=> nil
* a[-2..-4] #=> ""
* a[/[aeiou](.)\1/] #=> "ell"
* a[/[aeiou](.)\1/, 0] #=> "ell"
* a[/[aeiou](.)\1/, 1] #=> "l"
Expand Down

0 comments on commit 42f0ec9

Please sign in to comment.