summaryrefslogtreecommitdiffstats
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-01 09:51:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-01 09:51:05 +0000
commit85e1749a7c4e5de7b4bc19b2f4e9b563138900af (patch)
treeebc6f71f415ab4b5b44ab8d985042bc1fedea0f8 /random.c
parent8506a3000e5de2bab34295cea08490ba298ac81d (diff)
downloadruby-85e1749a7c4e5de7b4bc19b2f4e9b563138900af.tar.gz
ruby-85e1749a7c4e5de7b4bc19b2f4e9b563138900af.tar.xz
ruby-85e1749a7c4e5de7b4bc19b2f4e9b563138900af.zip
* random.c (random_float): rejects Infinity and NaN.
[ruby-core:24651] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/random.c b/random.c
index 7aefb4d4f..4a6299386 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;