summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 3 insertions, 1 deletions
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;
}