summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/string.c b/string.c
index 4e0d9fda39..9e9d911156 100644
--- a/string.c
+++ b/string.c
@@ -1392,7 +1392,11 @@ rb_string_value_cstr(volatile VALUE *ptr)
if (!s || memchr(s, 0, len)) {
rb_raise(rb_eArgError, "string contains null byte");
}
- if (s[len]) rb_str_modify(str);
+ if (s[len]) {
+ rb_str_modify(str);
+ s = RSTRING_PTR(str);
+ s[RSTRING_LEN(str)] = 0;
+ }
return s;
}