mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
6a23960f3f
commit
92f59c6d79
2 changed files with 16 additions and 16 deletions
|
@ -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>
|
Mon Apr 1 07:15:03 2013 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
|
||||||
|
|
||||||
* configure.in: use quadrigraph to put '[' or ']'. [Bug #8192]
|
* configure.in: use quadrigraph to put '[' or ']'. [Bug #8192]
|
||||||
|
|
26
numeric.c
26
numeric.c
|
@ -2049,20 +2049,17 @@ check_int(SIGNED_VALUE num)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_uint(VALUE num, int sign)
|
check_uint(unsigned long num, int sign)
|
||||||
{
|
{
|
||||||
static const VALUE mask = ~(VALUE)UINT_MAX;
|
|
||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
/* minus */
|
/* minus */
|
||||||
if ((num & mask) != mask || (num & ~mask) <= INT_MAX)
|
if (num < (unsigned long)INT_MIN)
|
||||||
#define VALUE_MSBMASK ((VALUE)1 << ((sizeof(VALUE) * CHAR_BIT) - 1))
|
rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned int'", (long)num);
|
||||||
rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num|VALUE_MSBMASK);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* plus */
|
/* plus */
|
||||||
if ((num & mask) != 0)
|
if (UINT_MAX < num)
|
||||||
rb_raise(rb_eRangeError, "integer %"PRIuVALUE " too big to convert to `unsigned int'", 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
|
static void
|
||||||
check_ushort(VALUE num, int sign)
|
check_ushort(unsigned long num, int sign)
|
||||||
{
|
{
|
||||||
static const VALUE mask = ~(VALUE)USHRT_MAX;
|
|
||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
/* minus */
|
/* minus */
|
||||||
if ((num & mask) != mask || (num & ~mask) <= SHRT_MAX)
|
if (num < (unsigned long)SHRT_MIN)
|
||||||
#define VALUE_MSBMASK ((VALUE)1 << ((sizeof(VALUE) * CHAR_BIT) - 1))
|
rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned short'", (long)num);
|
||||||
rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned short'", num|VALUE_MSBMASK);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* plus */
|
/* plus */
|
||||||
if ((num & mask) != 0)
|
if (USHRT_MAX < num)
|
||||||
rb_raise(rb_eRangeError, "integer %"PRIuVALUE " too big to convert to `unsigned short'", num);
|
rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned short'", num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue