From cab9751e97e6bfca2f34c8d52a818808ed559ebe Mon Sep 17 00:00:00 2001 From: kosaki Date: Mon, 24 Jan 2011 18:23:05 +0000 Subject: [PATCH] * object.c (rb_str_to_dbl): Fix again. use rb_str_tmp_new() instead ALLOC_N. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ object.c | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17ce263a96..c77cb7f25b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jan 24 22:26:33 2011 KOSAKI Motohiro + + * object.c (rb_str_to_dbl): Fix again. use rb_str_tmp_new() + instead ALLOC_N. + Mon Jan 24 21:50:48 2011 Tanaka Akira * vm_insnhelper.h: parenthesize macro arguments. diff --git a/object.c b/object.c index 97989fd82a..32777720ae 100644 --- a/object.c +++ b/object.c @@ -2246,7 +2246,7 @@ rb_str_to_dbl(VALUE str, int badcheck) char *s; long len; double ret; - char *alloced = NULL; + VALUE tmp = Qnil; StringValue(str); s = RSTRING_PTR(str); @@ -2256,15 +2256,18 @@ rb_str_to_dbl(VALUE str, int badcheck) rb_raise(rb_eArgError, "string for Float contains null byte"); } if (s[len]) { /* no sentinel somehow */ - char *p = alloced = ALLOC_N(char, len+1); + char *p; + + tmp = rb_str_tmp_new(len); + p = RSTRING_PTR(tmp); MEMCPY(p, s, char, len); p[len] = '\0'; s = p; } } ret = rb_cstr_to_dbl(s, badcheck); - if (alloced) - xfree(alloced); + if (tmp != Qnil) + rb_str_resize(tmp, 0); return ret; }