ruby-changes:27977
From: akr <ko1@a...>
Date: Mon, 1 Apr 2013 12:06:19 +0900 (JST)
Subject: [ruby-changes:27977] akr:r40029 (trunk): * numeric.c (check_uint): Take the 1st argument as unsigned long,
akr 2013-04-01 12:06:09 +0900 (Mon, 01 Apr 2013) New Revision: 40029 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40029 Log: * numeric.c (check_uint): Take the 1st argument as unsigned long, instead of VALUE. Refine the validity test conditions. (check_ushort): Ditto. Modified files: trunk/ChangeLog trunk/numeric.c Index: ChangeLog =================================================================== --- ChangeLog (revision 40028) +++ ChangeLog (revision 40029) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Apr 1 12:05:15 2013 Tanaka Akira <akr@f...> + + * numeric.c (check_uint): Take the 1st argument as unsigned long, + instead of VALUE. Refine the validity test conditions. + (check_ushort): Ditto. + Mon Apr 1 07:15:03 2013 Ayumu AIZAWA <ayumu.aizawa@g...> * configure.in: use quadrigraph to put '[' or ']'. [Bug #8192] Index: numeric.c =================================================================== --- numeric.c (revision 40028) +++ numeric.c (revision 40029) @@ -2049,20 +2049,17 @@ check_int(SIGNED_VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2049 } static void -check_uint(VALUE num, int sign) +check_uint(unsigned long num, int sign) { - static const VALUE mask = ~(VALUE)UINT_MAX; - if (sign) { /* minus */ - if ((num & mask) != mask || (num & ~mask) <= INT_MAX) -#define VALUE_MSBMASK ((VALUE)1 << ((sizeof(VALUE) * CHAR_BIT) - 1)) - rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num|VALUE_MSBMASK); + if (num < (unsigned long)INT_MIN) + rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned int'", (long)num); } else { /* plus */ - if ((num & mask) != 0) - rb_raise(rb_eRangeError, "integer %"PRIuVALUE " too big to convert to `unsigned int'", num); + if (UINT_MAX < num) + rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num); } } @@ -2137,20 +2134,17 @@ check_short(SIGNED_VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2134 } static void -check_ushort(VALUE num, int sign) +check_ushort(unsigned long num, int sign) { - static const VALUE mask = ~(VALUE)USHRT_MAX; - if (sign) { /* minus */ - if ((num & mask) != mask || (num & ~mask) <= SHRT_MAX) -#define VALUE_MSBMASK ((VALUE)1 << ((sizeof(VALUE) * CHAR_BIT) - 1)) - rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned short'", num|VALUE_MSBMASK); + if (num < (unsigned long)SHRT_MIN) + rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned short'", (long)num); } else { /* plus */ - if ((num & mask) != 0) - rb_raise(rb_eRangeError, "integer %"PRIuVALUE " too big to convert to `unsigned short'", num); + if (USHRT_MAX < num) + rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned short'", num); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/