summaryrefslogtreecommitdiffhomepage
path: root/src/numeric.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-02-25 00:47:02 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-02-25 00:47:02 +0900
commitc636386953f806c5edee574019cb3f923e8817f2 (patch)
treea4914cc5d5143ed1b18e10aa3eae5b1099a8d896 /src/numeric.c
parentddf9504558f88a664a9c7046ea104cbce9cc708e (diff)
downloadmruby-c636386953f806c5edee574019cb3f923e8817f2.tar.gz
mruby-c636386953f806c5edee574019cb3f923e8817f2.zip
avoid accessing uninitialized string; ref ac936fc
Diffstat (limited to 'src/numeric.c')
-rw-r--r--src/numeric.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c
index ec7f05b97..e081cf80a 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -19,9 +19,11 @@
#define ceil(f) ceilf(f)
#define fmod(x,y) fmodf(x,y)
#define FLO_MAX_DIGITS 7
+#define FLO_MAX_SIGN_LENGTH 3
#define FLO_EPSILON FLT_EPSILON
#else
#define FLO_MAX_DIGITS 14
+#define FLO_MAX_SIGN_LENGTH 10
#define FLO_EPSILON DBL_EPSILON
#endif
@@ -159,6 +161,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo)
}
}
if (beg >= 0) length = end - beg;
+ if (length > FLO_MAX_SIGN_LENGTH) length = FLO_MAX_SIGN_LENGTH;
}
if (abs(exp) + length >= FLO_MAX_DIGITS) {
@@ -166,7 +169,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo)
e = TRUE;
n = n / pow(10.0, exp);
if (isinf(n)) {
- if (s[0] == '-') {
+ if (s < c) { /* s[0] == '-' */
return mrb_str_new_lit(mrb, "-0.0");
}
else {