summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-21 09:48:51 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-21 09:48:51 +0000
commit1ac4e6d2746144598404487b67630b31288db8ae (patch)
treeeeb0da589bba38789e6c2d78e52ae0ec95fa775c /rational.c
parent15648bfda8c7ee29006dc8871985ce6e3d042237 (diff)
* rational.c (read_digits): due to a bit tighter rb_cstr_to_inum().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/rational.c b/rational.c
index 16b7e4b354..b72f85119a 100644
--- a/rational.c
+++ b/rational.c
@@ -1986,14 +1986,16 @@ static int
read_digits(const char **s, int strict,
VALUE *num, int *count)
{
+ char *b, *bb;
int us = 1, ret = 1;
- const char *b = *s;
if (!isdecimal(**s)) {
*num = ZERO;
return 0;
}
+ bb = b = ALLOCA_N(char, strlen(*s) + 1);
+
while (isdecimal(**s) || **s == '_') {
if (**s == '_') {
if (strict) {
@@ -2007,6 +2009,7 @@ read_digits(const char **s, int strict,
else {
if (count)
(*count)++;
+ *b++ = **s;
us = 0;
}
(*s)++;
@@ -2016,7 +2019,8 @@ read_digits(const char **s, int strict,
(*s)--;
} while (**s == '_');
conv:
- *num = rb_cstr_to_inum(b, 10, 0);
+ *b = '\0';
+ *num = rb_cstr_to_inum(bb, 10, 0);
return ret;
}