ruby-changes:17446
From: naruse <ko1@a...>
Date: Tue, 12 Oct 2010 17:50:40 +0900 (JST)
Subject: [ruby-changes:17446] Ruby:r29451 (trunk): * numeric (check_uint): set MSB for negative value.
naruse 2010-10-12 17:50:30 +0900 (Tue, 12 Oct 2010) New Revision: 29451 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29451 Log: * 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. Modified files: trunk/ChangeLog trunk/numeric.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29450) +++ ChangeLog (revision 29451) @@ -1,3 +1,12 @@ +Tue Oct 12 17:47:10 2010 NARUSE, Yui <naruse@r...> + + * 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@r...> * win32/win32.c (rb_w32_strerror): get English message first, instead Index: numeric.c =================================================================== --- numeric.c (revision 29450) +++ numeric.c (revision 29451) @@ -1791,7 +1791,8 @@ 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 @@ 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 @@ 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/