-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
etl::string is invalid if calling assign() with itself #1031
Comments
The first could be solved with a The second is more problematic. The only thing you could efficiently check is a |
Well, the issue only exists when you assign starting from (str/view).begin(). While not very efficient, would it work if assign did not call initialise() and instead only set current_size = 0? I believe it would fix my issue, but I'm not sure of all the ramifications. |
I think that could work. It would have to erase the unused portion of the string if the 'secure' flag was set. |
After some thought and experimentation, it is possible to stop a self assign from destroying the string, but it isn't possible to get The only option would be to throw an error if the address of the first element is within the address range of the string's buffer. (This has it's own issues) The STL doesn't do this, the standard just says that elements must not be within the address range of the string's buffer. Caveat Emptor. |
Fixed 20.40.0 |
If you assign a string to itself, the first character of the string is set to '0' because initialise() is called during assign(). Is this intentional?
Simple self assignment:
etl::string<32> str1 = "hello world";
str1.assign(str1);
Assignment to itself via string_view of itself:
etl::string<32> str = "hello world";
auto sv = etl::string_view(str);
str.assign(sv.begin(), sv.end());
The text was updated successfully, but these errors were encountered: