summaryrefslogtreecommitdiff
diff options
-rw-r--r--ChangeLog5
-rw-r--r--string.c4
2 files changed, 8 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 2b5ff01e43..47a7230220 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Apr 14 15:58:11 2010 Nobuyoshi Nakada <[email protected]>
+
+ * string.c (rb_string_value_cstr): make NUL terminated if it is
+ not done.
+
Mon Apr 12 21:47:41 2010 Nobuyoshi Nakada <[email protected]>
* LEGAL: separated the section for parse.c. contributed by Paul
diff --git a/string.c b/string.c
index 3df5415106..2d4e6ff23a 100644
--- a/string.c
+++ b/string.c
@@ -607,10 +607,12 @@ rb_string_value_cstr(ptr)
{
VALUE str = rb_string_value(ptr);
char *s = RSTRING(str)->ptr;
+ long len = RSTRING(str)->len;
- if (!s || RSTRING(str)->len != strlen(s)) {
+ if (!s || memchr(s, 0, len)) {
rb_raise(rb_eArgError, "string contains null byte");
}
+ if (s[len]) rb_str_modify(str);
return s;
}