merge revision(s) d71be7274b: [Backport #20873]

[Bug #20873] Consider `-FIXNUM_MIN` overflow

	`-FIXNUM_MIN` is usually greater than `FIXNUM_MAX` on platforms using
	two's complement representation.
This commit is contained in:
Takashi Kokubun 2025-01-14 17:42:54 -08:00
parent 42f043c189
commit 1ec258ab70
3 changed files with 6 additions and 2 deletions

View file

@ -811,7 +811,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (FIXNUM_P(num)) {
if ((SIGNED_VALUE)num < 0) {
long n = -FIX2LONG(num);
num = LONG2FIX(n);
num = LONG2NUM(n);
sign = -1;
}
}

View file

@ -227,6 +227,10 @@ class TestSprintf < Test::Unit::TestCase
bug11766 = '[ruby-core:71806] [Bug #11766]'
assert_equal("x"*10+" 1.0", sprintf("x"*10+"%8.1f", 1r), bug11766)
require 'rbconfig/sizeof'
fmin, fmax = RbConfig::LIMITS.values_at("FIXNUM_MIN", "FIXNUM_MAX")
assert_match(/\A-\d+\.\d+\z/, sprintf("%f", Rational(fmin, fmax)))
end
def test_rational_precision

View file

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 110
#define RUBY_PATCHLEVEL 111
#include "ruby/version.h"
#include "ruby/internal/abi.h"