* object.c (rb_str_to_dbl): use ALLOC_N instead ALLOCA_N because

ALLOC_N may cause stack overflow.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2011-01-24 12:30:02 +00:00
parent 76789bbbb3
commit 2ec31553ea
2 changed files with 12 additions and 3 deletions

View File

@ -1,3 +1,8 @@
Mon Jan 24 21:28:34 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* object.c (rb_str_to_dbl): use ALLOC_N instead ALLOCA_N because
ALLOC_N may cause stack overflow.
Mon Jan 24 21:04:45 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Jan 24 21:04:45 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (rb_invalid_str): prevent intermediate variable from GC. * error.c (rb_invalid_str): prevent intermediate variable from GC.

View File

@ -2245,6 +2245,8 @@ rb_str_to_dbl(VALUE str, int badcheck)
{ {
char *s; char *s;
long len; long len;
double ret;
char *alloced = NULL;
StringValue(str); StringValue(str);
s = RSTRING_PTR(str); s = RSTRING_PTR(str);
@ -2254,14 +2256,16 @@ rb_str_to_dbl(VALUE str, int badcheck)
rb_raise(rb_eArgError, "string for Float contains null byte"); rb_raise(rb_eArgError, "string for Float contains null byte");
} }
if (s[len]) { /* no sentinel somehow */ if (s[len]) { /* no sentinel somehow */
char *p = ALLOCA_N(char, len+1); char *p = alloced = ALLOC_N(char, len+1);
MEMCPY(p, s, char, len); MEMCPY(p, s, char, len);
p[len] = '\0'; p[len] = '\0';
s = p; s = p;
} }
} }
return rb_cstr_to_dbl(s, badcheck); ret = rb_cstr_to_dbl(s, badcheck);
if (alloced)
xfree(alloced);
return ret;
} }
VALUE VALUE