summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorMichael Kohl <me@citizen428.net>2020-07-18 23:18:40 +0700
committerGitHub <noreply@github.com>2020-07-19 01:18:40 +0900
commit8a5ad2b77d7a24e4f8f4fef179ae5efced935f91 (patch)
tree5fe26555ef640a04909c36315659e15bd132e3b2 /range.c
parentb4e784434c54348283c079efb1b8ab9de13c0603 (diff)
Fix Range#max for beginless Integer ranges [Bug #17034]
* Fix Range#max for beginless Integer ranges * Update test/ruby/test_range.rb * Fix formatting https://github.com/ruby/ruby/pull/3328 Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Notes
Notes: Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'range.c')
-rw-r--r--range.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/range.c b/range.c
index 93cf126f51..124d9faa51 100644
--- a/range.c
+++ b/range.c
@@ -1220,16 +1220,17 @@ range_max(int argc, VALUE *argv, VALUE range)
rb_raise(rb_eRangeError, "cannot get the maximum of endless range");
}
+ VALUE b = RANGE_BEG(range);
+
if (rb_block_given_p() || (EXCL(range) && !nm) || argc) {
- if (NIL_P(RANGE_BEG(range))) {
+ if (NIL_P(b)) {
rb_raise(rb_eRangeError, "cannot get the maximum of beginless range with custom comparison method");
}
return rb_call_super(argc, argv);
}
else {
struct cmp_opt_data cmp_opt = { 0, 0 };
- VALUE b = RANGE_BEG(range);
- int c = OPTIMIZED_CMP(b, e, cmp_opt);
+ int c = NIL_P(b) ? -1 : OPTIMIZED_CMP(b, e, cmp_opt);
if (c > 0)
return Qnil;