-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String.clone is unsafe #39
Comments
ping @MartinNowak can you identify what the purpose of the internal String type is for? I understand you want to be @safe unittest {
const(char)[] dangling;
{
String s1;
s1 ~= "hello";
dangling = s1[];
}
writeln(dangling); // uses now-freed memory
} Edit: is this supposed to be depending on dip1000 to ensure it doesn't compile? I can't get the unittests to build with -dip1000, so maybe that is the intention. But, reallocation via appending could easily free the original, so there is still that problem. |
Indeed there was some talk about implementing safe nogc strings at that time. So I tried how far scope would work. It had many deficiencies at that time. |
I was more thinking about just using more allocations to avoid memory issues. But I wasn't 100% sure what the different constructors were intended for. |
Current implementation of String.clone does not duplicate the string, it simply sets a new reference. If the original string is freed or reallocated, the new clone is now dangling.
The text was updated successfully, but these errors were encountered: