From 232257238acfaf3c34f3e6c4b2d6e1200fd217e8 Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 12 Oct 2010 08:50:30 +0000 Subject: [PATCH] * 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 --- ChangeLog | 9 +++++++++ numeric.c | 15 +++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e2158be2f..29cf0c5716 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Oct 12 17:47:10 2010 NARUSE, Yui + + * 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 * win32/win32.c (rb_w32_strerror): get English message first, instead diff --git a/numeric.c b/numeric.c index abc3b3efdd..9b01acfd10 100644 --- a/numeric.c +++ b/numeric.c @@ -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;