aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--numeric.c7
2 files changed, 9 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7e8646db1b..e941dda1cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Oct 13 14:58:09 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * numeric.c (rb_num_to_uint): fix 32bit logic.
+
Wed Oct 13 12:53:43 2010 NARUSE, Yui <naruse@ruby-lang.org>
* numeric.c (rb_num_to_uint): added to check the range of arguments.
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