summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-05-02 22:50:55 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-05-02 22:50:55 +0900
commit2d4c092de755752ecaf1d4b1240bab5a725049f2 (patch)
tree19519b2e03ea880906e836353faa83b32cd92e29 /src/string.c
parent028e34d3452acd1eb5602b78ff5c52f4dbb8a1eb (diff)
downloadmruby-2d4c092de755752ecaf1d4b1240bab5a725049f2.tar.gz
mruby-2d4c092de755752ecaf1d4b1240bab5a725049f2.zip
Need to call `mrb_str_modify()` in `mrb_str_cat_str()`; fix #4018
If `str` and `str2` are the same string object `str->ptr` may be rewritten by `mrb_str_modify()`.
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
index e4bfd034c..5cca6d460 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2615,6 +2615,9 @@ mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr)
MRB_API mrb_value
mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2)
{
+ if (mrb_str_ptr(str) == mrb_str_ptr(str2)) {
+ mrb_str_modify(mrb, mrb_str_ptr(str));
+ }
return mrb_str_cat(mrb, str, RSTRING_PTR(str2), RSTRING_LEN(str2));
}