Assigning a view of a String to itself corrupts the String
jlaumon opened this issue · comments
Hi,
I just noticed doing something like:
String s = "something";
s = s.shortenedBy(1);
gets you a dangling pointer inside s
, because the operator= destroys this before assigning the new value
plywood/repos/plywood/src/runtime/ply-runtime/string/String.h
Lines 96 to 103 in f00ffdd
Actually, now that I'm writing this, I see that Array
does the same (and Array::append
too, the parameter is a ref that might point inside the array that gets resized 🙊).
Sorry, I feel bad for reporting this without a PR for fixing it 😅
Great catch! Will fix soon, thanks.
For Array::append
and Array::extend
, I decided to disallow passing the Array's own items back into itself.
Sounds fair enough!
Thanks a lot for fixing that so fast!