summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--random.c6
2 files changed, 11 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7e030b6331..67b8869151 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Aug 1 18:50:53 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * random.c (random_float): rejects Infinity and NaN.
+ [ruby-core:24651]
+
Sat Aug 1 18:34:52 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* tool/rbinstall.rb (gem): suppressed warnings.
diff --git a/random.c b/random.c
index 7aefb4d4fb..4a62993864 100644
--- a/random.c
+++ b/random.c
@@ -196,6 +196,8 @@ genrand_real(struct MT *mt)
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
+#include <math.h>
+#include <errno.h>
typedef struct {
VALUE seed;
@@ -939,6 +941,10 @@ random_float(int argc, VALUE *argv, VALUE obj)
!NIL_P(vmax = rb_to_float(vmax)) ||
(vmax = range_values(vmax, &beg)) != Qfalse) {
max = RFLOAT_VALUE(vmax);
+ if (isinf(max) || isnan(max)) {
+ VALUE error = INT2FIX(EDOM);
+ rb_exc_raise(rb_class_new_instance(1, &error, rb_eSystemCallError));
+ }
}
else {
beg = Qundef;