* numeric.c (check_uint): Take the 1st argument as unsigned long,

instead of VALUE.  Refine the validity test conditions.
  (check_ushort): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-04-01 03:06:09 +00:00
Родитель 6a23960f3f
Коммит 92f59c6d79
2 изменённых файлов: 16 добавлений и 16 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Mon Apr 1 12:05:15 2013 Tanaka Akira <akr@fsij.org>
* 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@gmail.com>
* configure.in: use quadrigraph to put '[' or ']'. [Bug #8192]

Просмотреть файл

@ -2049,20 +2049,17 @@ check_int(SIGNED_VALUE num)
}
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)
}
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);
}
}