#159: "%d" with large integer argument gives conversion error
---------------------------------+------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: [EMAIL PROTECTED]
Type: defect | Status: new
Priority: major | Milestone:
Component: MacRuby | Keywords:
---------------------------------+------------------------------------------
The following script reproduces the error easily:
{{{
N = 34363859232
p N
p N.class
puts "%d" % N
}}}
This results in the following exception:
{{{
01.rb:5:in `%': integer 34363859232 too big to convert to `int'
(RangeError)
}}}
When run in ruby 1.9, the output shows that N is a Bignum. When run in
macruby, the output shows that N is a fixnum. This appears to be due to
bignum.c line 523:
{{{
if (len <= (sizeof(long)*CHAR_BIT)) {
}}}
Apparently, in macruby, sizeof(long) is 8, which means bignums are only
instantiated for integers larger than 64 bits or so, and in the above
example, the integer is only 44 bits.
Even though the bignums are only created based on sizeof(long), the
rb_str_format function in sprintf.c uses FIX2LONG for converting the VALUE
to a long int, and FIX2LONG uses INT_MIN and INT_MAX to check the bounds
of the integer.
I'm not sure what the safest way to fix this is. Should check_int (and
others?) in numeric.c be comparing against larger boundary numbers,
instead of INT_MIN/MAX?
--
Ticket URL: <http://www.macruby.org/trac/ticket/159>
MacRuby <http://macruby.org/>
_______________________________________________
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel