Skip to content

Commit 1ec258a

Browse files
committed
merge revision(s) d71be72: [Backport #20873]
[Bug #20873] Consider `-FIXNUM_MIN` overflow `-FIXNUM_MIN` is usually greater than `FIXNUM_MAX` on platforms using two's complement representation.
1 parent 42f043c commit 1ec258a

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

sprintf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
811811
if (FIXNUM_P(num)) {
812812
if ((SIGNED_VALUE)num < 0) {
813813
long n = -FIX2LONG(num);
814-
num = LONG2FIX(n);
814+
num = LONG2NUM(n);
815815
sign = -1;
816816
}
817817
}

test/ruby/test_sprintf.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def test_rational
227227

228228
bug11766 = '[ruby-core:71806] [Bug #11766]'
229229
assert_equal("x"*10+" 1.0", sprintf("x"*10+"%8.1f", 1r), bug11766)
230+
231+
require 'rbconfig/sizeof'
232+
fmin, fmax = RbConfig::LIMITS.values_at("FIXNUM_MIN", "FIXNUM_MAX")
233+
assert_match(/\A-\d+\.\d+\z/, sprintf("%f", Rational(fmin, fmax)))
230234
end
231235

232236
def test_rational_precision

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 6
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 110
14+
#define RUBY_PATCHLEVEL 111
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)