Use rb_len_t for string lengths in numeric conversions

rb_big_pack() and rb_big_unpack() keep `long`, because num_longs counts the words of an `unsigned long` buffer rather than a String or Array length.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Hiroshi SHIBATAandClaude Opus 5 committed 2026-10-09 14:00:15 +09:00
1 parent 2c00037d72
commit 593b42ec70
5 files changed
+10 -10
Notes: git 2026-10-09 05:02:08 +00:00

No files matched your search

+4 -4
View File
@@ -4334,7 +4334,7 @@ rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception)
{
VALUE ret;
const char *s;
long len;
rb_len_t len;
char *end;
StringValue(str);
@@ -4807,9 +4807,9 @@ struct big2str_struct {
static void
big2str_alloc(struct big2str_struct *b2s, size_t len)
{
if (LONG_MAX-1 < len)
if (RB_LEN_MAX-1 < len)
rb_raise(rb_eArgError, "too big number");
b2s->result = rb_usascii_str_new(0, (long)(len + 1)); /* plus one for sign */
b2s->result = rb_usascii_str_new(0, (rb_len_t)(len + 1)); /* plus one for sign */
b2s->ptr = RSTRING_PTR(b2s->result);
if (b2s->negative)
*b2s->ptr++ = '-';
@@ -5136,7 +5136,7 @@ big2str_generic(VALUE x, int base)
RB_GC_GUARD(x);
*b2s_data.ptr = '\0';
rb_str_resize(b2s_data.result, (long)(b2s_data.ptr - RSTRING_PTR(b2s_data.result)));
rb_str_resize(b2s_data.result, (rb_len_t)(b2s_data.ptr - RSTRING_PTR(b2s_data.result)));
RB_GC_GUARD(x);
return b2s_data.result;
+1 -1
View File
@@ -1728,7 +1728,7 @@ nucomp_marshal_load(VALUE self, VALUE a)
{
Check_Type(a, T_ARRAY);
if (RARRAY_LEN(a) != 2)
rb_raise(rb_eArgError, "marshaled complex must have an array whose length is 2 but %ld", RARRAY_LEN(a));
rb_raise(rb_eArgError, "marshaled complex must have an array whose length is 2 but %"PRIdLEN, RARRAY_LEN(a));
rb_ivar_set(self, id_i_real, RARRAY_AREF(a, 0));
rb_ivar_set(self, id_i_imag, RARRAY_AREF(a, 1));
return self;
+3 -3
View File
@@ -980,7 +980,7 @@ flo_to_s(VALUE flt)
rb_str_cat(s, buf, digs + 1);
}
else if (decpt <= DBL_DIG) {
long len;
rb_len_t len;
char *ptr;
rb_str_cat(s, buf, digs);
rb_str_resize(s, (len = RSTRING_LEN(s)) + decpt - digs + 2);
@@ -996,7 +996,7 @@ flo_to_s(VALUE flt)
}
}
else if (decpt > -4) {
long len;
rb_len_t len;
char *ptr;
rb_str_cat(s, "0.", 2);
rb_str_resize(s, (len = RSTRING_LEN(s)) - decpt + digs);
@@ -5840,7 +5840,7 @@ rb_int_digits_bigbase(VALUE num, VALUE base)
digits = rb_ary_new_from_args(1, num);
while (RARRAY_LEN(bases)) {
VALUE b = rb_ary_pop(bases);
long i, last_idx = RARRAY_LEN(digits) - 1;
rb_len_t i, last_idx = RARRAY_LEN(digits) - 1;
for(i = last_idx; i >= 0; i--) {
VALUE n = RARRAY_AREF(digits, i);
VALUE divmod = rb_int_divmod(n, b);
+1 -1
View File
@@ -3697,7 +3697,7 @@ static double
rb_str_to_dbl_raise(VALUE str, int badcheck, int raise, int *error)
{
char *s;
long len;
rb_len_t len;
double ret;
VALUE v = 0;
+1 -1
View File
@@ -1911,7 +1911,7 @@ nurat_marshal_load(VALUE self, VALUE a)
Check_Type(a, T_ARRAY);
if (RARRAY_LEN(a) != 2)
rb_raise(rb_eArgError, "marshaled rational must have an array whose length is 2 but %ld", RARRAY_LEN(a));
rb_raise(rb_eArgError, "marshaled rational must have an array whose length is 2 but %"PRIdLEN, RARRAY_LEN(a));
num = RARRAY_AREF(a, 0);
den = RARRAY_AREF(a, 1);