diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-06 12:59:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-06 12:59:59 +0000 |
commit | 9deecfc4531cc038a0c27a72c316dafb9aa2bc23 (patch) | |
tree | 41cc1280bbd257487739a78032c874bd6583b0a3 /range.c | |
parent | 814b7b544848ffd41e97b3a0af2db7baee146764 (diff) | |
download | ruby-9deecfc4531cc038a0c27a72c316dafb9aa2bc23.tar.gz |
range.c: return nil for empty range
* range.c (range_last): return nil for empty range, or in the case the
predecessor is smaller than the begin. [Bug #8739]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r-- | range.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -891,8 +891,15 @@ range_last(int argc, VALUE *argv, VALUE range) VALUE e = RANGE_END(range); if (!EXCL(range)) return e; /* inclusive, the end is the last */ /* exclusive, the last is previous to the end */ - if (FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric)) - return rb_int_pred(e); + if (FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric)) { + VALUE pred = rb_int_pred(e); + if (!r_lt(RANGE_BEG(range), pred)) { + /* TODO: what should be returned, or should raise an + * exception? */ + pred = Qnil; + } + return pred; + } /* fallback to Array */ } |