summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-13 05:58:35 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-13 05:58:35 +0000
commite79fbf3dfef38883a4173b4d1a58448343407f2f (patch)
treee6551dc9f4a389548ec3f663d8acaeadfc45a8df /numeric.c
parenta01e62831818ed1c8c00e79991b8f34c02327127 (diff)
* numeric.c (rb_num_to_uint): fix 32bit logic.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/numeric.c b/numeric.c
index 4b3cf595cb..c27187f4f4 100644
--- a/numeric.c
+++ b/numeric.c
@@ -122,7 +122,9 @@ rb_num_to_uint(VALUE val, unsigned int *ret)
#define NUMERR_TOOLARGE 3
if (FIXNUM_P(val)) {
long v = FIX2LONG(val);
- if (v > UINT_MAX) return NUMERR_TOOLARGE;
+#if SIZEOF_INT < SIZEOF_LONG
+ if (v > (long)UINT_MAX) return NUMERR_TOOLARGE;
+#endif
if (v < 0) return NUMERR_NEGATIVE;
*ret = (unsigned int)v;
return 0;
@@ -136,7 +138,8 @@ rb_num_to_uint(VALUE val, unsigned int *ret)
return NUMERR_TOOLARGE;
#else
/* long is 32bit */
- if (RBIGNUM_LEN(x) > DIGSPERLONG) return NUMERR_TOOLARGE;
+#define DIGSPERLONG (SIZEOF_LONG/SIZEOF_BDIGITS)
+ if (RBIGNUM_LEN(val) > DIGSPERLONG) return NUMERR_TOOLARGE;
*ret = (unsigned int)rb_big2ulong((VALUE)val);
return 0;
#endif