ruby-changes:25747
From: tadf <ko1@a...>
Date: Thu, 22 Nov 2012 20:33:03 +0900 (JST)
Subject: [ruby-changes:25747] tadf:r37804 (trunk): * complex.c (string_to_c_strict, string_to_c): check NUL.
tadf 2012-11-22 20:32:52 +0900 (Thu, 22 Nov 2012) New Revision: 37804 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37804 Log: * complex.c (string_to_c_strict, string_to_c): check NUL. * rational.c (string_to_r_strict, string_to_r): ditto. Modified files: trunk/ChangeLog trunk/complex.c trunk/rational.c Index: complex.c =================================================================== --- complex.c (revision 37803) +++ complex.c (revision 37804) @@ -1776,16 +1776,25 @@ static VALUE string_to_c_strict(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); - if (memchr(s, 0, RSTRING_LEN(self))) + if (!s || memchr(s, '\0', RSTRING_LEN(self))) rb_raise(rb_eArgError, "string contains null byte"); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + if (!parse_comp(s, 1, &num)) { VALUE ins = f_inspect(self); rb_raise(rb_eArgError, "invalid value for convert(): %s", @@ -1819,13 +1828,22 @@ static VALUE string_to_c(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + (void)parse_comp(s, 0, &num); return num; Index: ChangeLog =================================================================== --- ChangeLog (revision 37803) +++ ChangeLog (revision 37804) @@ -1,3 +1,8 @@ +Thu Nov 22 20:32:07 2012 Tadayoshi Funaba <tadf@d...> + + * complex.c (string_to_c_strict, string_to_c): check NUL. + * rational.c (string_to_r_strict, string_to_r): ditto. + Thu Nov 22 20:21:45 2012 KOSAKI Motohiro <kosaki.motohiro@g...> * Makefile.in (.dmyh.h): removed $(VPATH). GNU make don't Index: rational.c =================================================================== --- rational.c (revision 37803) +++ rational.c (revision 37804) @@ -2143,16 +2143,25 @@ static VALUE string_to_r_strict(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); - if (memchr(s, 0, RSTRING_LEN(self))) + if (!s || memchr(s, '\0', RSTRING_LEN(self))) rb_raise(rb_eArgError, "string contains null byte"); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + if (!parse_rat(s, 1, &num)) { VALUE ins = f_inspect(self); rb_raise(rb_eArgError, "invalid value for convert(): %s", @@ -2188,13 +2197,22 @@ static VALUE string_to_r(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + (void)parse_rat(s, 0, &num); if (RB_TYPE_P(num, T_FLOAT)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/