-
-
Notifications
You must be signed in to change notification settings - Fork 416
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.recalc chops last byte when recalc'd _size == _alloc #1446
Comments
I'm not even sure I believe that For now, I would suggest changing the documented behaviour to say "If a null terminator byte is not found within the allocated length, the entire allocated length will be used as the size". Like many of the bugs you've found recently, this should have been changed when we removed the null terminator requirement, but it was overlooked (the blame should mainly fall on me for this). |
Trouble is that even if a null terminator is found, we really have no idea if it was what the user intended, since pre-allocated space is not zeroed. With pre-allocation, which seems to be almost always the case, the method would seem to be non-deterministic. Even if we do I was about to open a PR, but my master ended up getting an unexpected merge, so I'm fixing that first. I'll hold off on the PR for now until a final decision is made. |
We discussed on the sync call that the documented/implemented behaviour of This behaviour would not reveal any non-deterministic bytes from the pre-allocation, and would not cause any problems if you happen to call the method on a String that never actually had its buffer changed by an FFI call - the same bytes from the buffer that were exposed before would now still be exposed. |
Sounds good @jemc. I'll finish this up in a few hours. |
@jemc I just submitted a PR. Still seems non-deterministic since we won't know if a preallocated byte will be null, but I guess there's probably no way around that. |
Yeah, it's true - but as long as this method exists to do what it does, we have that problem... It's only necessary because some C functions won't return the number of bytes written to the buffer. |
The `String.recalc` method would truncate the final byte in a string where no null terminator was found. The behavior and documentation has been changed so that in the case of no null terminator, the `_size` of the string remains unchanged. Fixes #1446
This is similar to the issue with
.trucate()
, #1427.Output:
The fix is simple enough, though in order to maintain the documented behavior, an extra byte will need to be
reserve()
'd, causing an allocation to the next power of two.The text was updated successfully, but these errors were encountered: