From 3a6227f5ee9358bd8d0d093d0b4a7f3400e17e78 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 20 May 2009 16:43:41 +0000 Subject: * include/ruby/ruby.h (rb_long2int, RARRAY_LENINT): check long to cast to int. [ruby-dev:38508] * struct.c, vm_eval.c, vm_insnhelper.c: use RARRAY_LENINT. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 5b051f145..9da8e1178 100644 --- a/numeric.c +++ b/numeric.c @@ -1630,21 +1630,19 @@ rb_num2ulong(VALUE val) } #if SIZEOF_INT < SIZEOF_VALUE +void +rb_out_of_int(SIGNED_VALUE num) +{ + rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `int'", + num, num < 0 ? "small" : "big"); +} + static void check_int(SIGNED_VALUE num) { - const char *s; - - if (num < INT_MIN) { - s = "small"; - } - else if (num > INT_MAX) { - s = "big"; - } - else { - return; + if ((SIGNED_VALUE)(int)num != num) { + rb_out_of_int(num); } - rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `int'", num, s); } static void -- cgit