summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-06 12:59:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-06 12:59:59 +0000
commit9deecfc4531cc038a0c27a72c316dafb9aa2bc23 (patch)
tree41cc1280bbd257487739a78032c874bd6583b0a3 /range.c
parent814b7b544848ffd41e97b3a0af2db7baee146764 (diff)
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.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/range.c b/range.c
index c805848..0076254 100644
--- a/range.c
+++ b/range.c
@@ -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 */
}