-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove unnecessary null terminator #1360
Remove unnecessary null terminator #1360
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1360 +/- ##
==========================================
- Coverage 95.41% 95.40% -0.02%
==========================================
Files 443 443
Lines 13402 13349 -53
==========================================
- Hits 12787 12735 -52
+ Misses 615 614 -1
Continue to review full report at Codecov.
|
This one seems only be used in tests, can you check if we can remove it? thanks! |
std::string is not null-terminated, probably not needed, maybe it was added as a safety net for the case if std::string contents is used as C string. |
I don't think so, some reasons:
|
Suggest you don't remove this:
|
Std::string can be initialized with null-terminated string, or with pointer and explicit size, both are fine. In TWStringUTF8Bytes, we use .data(), which is not correct at first sight, this is the real problem. Correct should be .c_str(). Should be changed definitely. However, depending on implementation, data() may return null terminated always. In fact, what I found: So it looks like data() is actually fine, but nonetheless it should be c_str(), and then there is no need to add null terminator ourselves. |
* Remove unnecessary null terminator * Return guaranteed null-terminated string in TWStringUTF8Bytes Co-authored-by: Catenocrypt <[email protected]>
* Remove unnecessary null terminator * Return guaranteed null-terminated string in TWStringUTF8Bytes Co-authored-by: Catenocrypt <[email protected]>
Description
No need to append
size
number of '\0' in function TWStringCreateWithRawBytes. TWStringSize would output2 * size
without this fix, I think this is unnecessary.Just like TWStringCreateWithUTF8Bytes, we don't append '\0'. We also no need to append '\0' in function TWStringCreateWithRawBytes.
Testing instructions
Types of changes
Checklist
[WIP]
if necessary.