diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-04 04:36:00 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-04 04:36:00 +0000 |
commit | 3fcb3949720e406e543c6e7fcf8ac33d5837e859 (patch) | |
tree | 6c77e3748e64602cd3d0a8d6b084196b2945b628 | |
parent | d1911459aed44a294cd8d2ef8e5c723c656f63ca (diff) |
merge revision(s) 18100,18129:
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
fixed [ruby-dev:33683]
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
about 64bit positive value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@18331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | numeric.c | 25 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 26 insertions, 10 deletions
@@ -1,3 +1,12 @@ +Mon Aug 4 13:31:41 2008 NAKAMURA Usaku <usa@ruby-lang.org> + + * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check + about 64bit positive value. +Mon Aug 4 13:31:41 2008 NAKAMURA Usaku <usa@ruby-lang.org> + + * numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check. + fixed [ruby-dev:33683] + Thu Jul 17 21:42:07 2008 URABE Shyouhei <shyouhei@ruby-lang.org> * lib/net/smtp.rb (Net::SMTP::start): revert to avoid RFC2821 @@ -1600,11 +1600,21 @@ check_int(num) } static void -check_uint(num) +check_uint(num, sign) unsigned long num; + VALUE sign; { - if (num > UINT_MAX) { - rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num); + static const unsigned long mask = ~(unsigned long)UINT_MAX; + + if (RTEST(sign)) { + /* minus */ + if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL) + rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned int'", num); + } + else { + /* plus */ + if ((num & mask) != 0) + rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num); } } @@ -1634,9 +1644,7 @@ rb_num2uint(val) { unsigned long num = rb_num2ulong(val); - if (RTEST(rb_funcall(INT2FIX(0), '<', 1, val))) { - check_uint(num); - } + check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0))); return num; } @@ -1650,9 +1658,8 @@ rb_fix2uint(val) return rb_num2uint(val); } num = FIX2ULONG(val); - if (FIX2LONG(val) > 0) { - check_uint(num); - } + + check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0))); return num; } #else @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2008-08-04" #define RUBY_VERSION_CODE 187 #define RUBY_RELEASE_CODE 20080804 -#define RUBY_PATCHLEVEL 64 +#define RUBY_PATCHLEVEL 65 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 |