diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-12 08:50:30 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-12 08:50:30 +0000 |
commit | 232257238acfaf3c34f3e6c4b2d6e1200fd217e8 (patch) | |
tree | 35b3725604669b7aca8d308e335770ec5e02d1d4 | |
parent | fb44f02aa11674b5754f1053d40797ab6973b41d (diff) | |
download | ruby-232257238acfaf3c34f3e6c4b2d6e1200fd217e8.tar.gz |
* numeric (check_uint): set MSB for negative value.
* numeric (rb_num2uint): return value's type of rb_num2ulong
is VALUE.
* numeric (int_chr): variable i can't be negative.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | numeric.c | 15 |
2 files changed, 16 insertions, 8 deletions
@@ -1,3 +1,12 @@ +Tue Oct 12 17:47:10 2010 NARUSE, Yui <naruse@ruby-lang.org> + + * numeric (check_uint): set MSB for negative value. + + * numeric (rb_num2uint): return value's type of rb_num2ulong + is VALUE. + + * numeric (int_chr): variable i can't be negative. + Tue Oct 12 16:04:37 2010 NAKAMURA Usaku <usa@ruby-lang.org> * win32/win32.c (rb_w32_strerror): get English message first, instead @@ -1791,7 +1791,8 @@ check_uint(VALUE num, VALUE sign) if (RTEST(sign)) { /* minus */ if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL) - rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num); +#define MSBMASK (1L << ((sizeof(long) * CHAR_BIT) - 1)) + rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num|MSBMASK); } else { /* plus */ @@ -1821,10 +1822,10 @@ rb_fix2int(VALUE val) unsigned long rb_num2uint(VALUE val) { - unsigned long num = rb_num2ulong(val); + VALUE num = rb_num2ulong(val); check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0))); - return num; + return (unsigned long)num; } unsigned long @@ -2091,13 +2092,11 @@ int_chr(int argc, VALUE *argv, VALUE num) switch (argc) { case 0: - if (i < 0) { - out_of_range: - rb_raise(rb_eRangeError, "%d out of char range", i); - } if (0xff < i) { enc = rb_default_internal_encoding(); - if (!enc) goto out_of_range; + if (!enc) { + rb_raise(rb_eRangeError, "%d out of char range", i); + } goto decode; } c = (char)i; |