summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-14 05:21:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-14 05:21:58 +0000
commita8e795ca530e17dd28c4586344b0e2ab93bcf8b0 (patch)
treeadc07f0093eb7fd8b72fe13b77860b7a5ea3db75 /util.c
parent694d70cace59fcaa7517f5e2097bdf1fe586215d (diff)
* util.c (rv_strdup): macro to duplicate nul-terminated string.
[ruby-core:22852] * util.c (ruby_dtoa): allocates one more byte to get rid of buffer overrun. a patch from Charlie Savage at [ruby-core:22604]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@22947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/util.c b/util.c
index e74277e679..2bf6555096 100644
--- a/util.c
+++ b/util.c
@@ -3116,13 +3116,15 @@ nrv_alloc(const char *s, char **rve, int n)
{
char *rv, *t;
- t = rv = rv_alloc(n);
+ t = rv = rv_alloc(n+1);
while ((*t = *s++) != 0) t++;
if (rve)
*rve = t;
return rv;
}
+#define rv_strdup(s, rve) nrv_alloc(s, rve, strlen(s)+1)
+
/* freedtoa(s) must be used to free values s returned by dtoa
* when MULTIPLE_THREADS is #defined. It should be used in all cases,
* but for consistency with earlier versions of dtoa, it is optional
@@ -3256,9 +3258,9 @@ dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
*decpt = 9999;
#ifdef IEEE_Arith
if (!word1(d) && !(word0(d) & 0xfffff))
- return nrv_alloc("Infinity", rve, 8);
+ return rv_strdup("Infinity", rve);
#endif
- return nrv_alloc("NaN", rve, 3);
+ return rv_strdup("NaN", rve);
}
#endif
#ifdef IBM
@@ -3266,7 +3268,7 @@ dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
if (!dval(d)) {
*decpt = 1;
- return nrv_alloc("0", rve, 1);
+ return rv_strdup("0", rve);
}
#ifdef SET_INEXACT