-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: Change occurences of c_str() used with size() to data() #17280
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
Conversation
Using `data()` better communicates the intent here. Also, depending on how `c_str()` is implemented, this fixes undefined behavior: The part of the string after the first NULL character might have undefined contents.
Code review ACK f3b51eb |
Concept ACK What about linting this to make sure this is a one-time fix-up? Suggested lint command:
|
Maybe—It could catch some of them, I guess. But only if they're on the same line? |
@laanwj Correct, multi-line search with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK f3b51eb. Most of these calls (including one in crypter.cpp) are passing text strings, not binary strings likely to contain \0
and were probably safe before, but much better to avoid the possibility of bugs like this.
We are using C++11 and according to https://en.cppreference.com/w/cpp/string/basic_string/c_str this is safe.
I have removed the "bug" label and added the "Refactoring" label. Concept ACK, though. |
ACK f3b51eb -- diff looks correct, |
… to data() f3b51eb Fix occurences of c_str() used with size() to data() (Wladimir J. van der Laan) Pull request description: Using `data()` better communicates the intent here. ~~Also, depending on how `c_str()` is implemented, this fixes undefined behavior: The part of the string after the first NULL character might have undefined contents (or even be inaccessible, worst case).~~ Apparently [this is no longer an issue with C++11](#17281 (comment)). ACKs for top commit: fjahr: Code review ACK f3b51eb practicalswift: ACK f3b51eb -- diff looks correct, `data()` more idiomatic ryanofsky: Code review ACK f3b51eb. Most of these calls (including one in crypter.cpp) are passing text strings, not binary strings likely to contain `\0` and were probably safe before, but much better to avoid the possibility of bugs like this. Tree-SHA512: 842e1bdd37efc4ece2ecb87ca34962aafef0a192180051def630607e349dc9c8b4e562481fff3de474515f493b4ee3ea53b00269a801a66e625326a38dfce5b8
… size() to data() f3b51eb Fix occurences of c_str() used with size() to data() (Wladimir J. van der Laan) Pull request description: Using `data()` better communicates the intent here. ~~Also, depending on how `c_str()` is implemented, this fixes undefined behavior: The part of the string after the first NULL character might have undefined contents (or even be inaccessible, worst case).~~ Apparently [this is no longer an issue with C++11](bitcoin#17281 (comment)). ACKs for top commit: fjahr: Code review ACK f3b51eb practicalswift: ACK f3b51eb -- diff looks correct, `data()` more idiomatic ryanofsky: Code review ACK f3b51eb. Most of these calls (including one in crypter.cpp) are passing text strings, not binary strings likely to contain `\0` and were probably safe before, but much better to avoid the possibility of bugs like this. Tree-SHA512: 842e1bdd37efc4ece2ecb87ca34962aafef0a192180051def630607e349dc9c8b4e562481fff3de474515f493b4ee3ea53b00269a801a66e625326a38dfce5b8
…e() to data() Summary: Fix occurences of c_str() used with size() to data() (Wladimir J. van der Laan) Pull request description: Using `data()` better communicates the intent here. ~~Also, depending on how `c_str()` is implemented, this fixes undefined behavior: The part of the string after the first NULL character might have undefined contents (or even be inaccessible, worst case).~~ Apparently [this is no longer an issue with C++11](bitcoin/bitcoin#17281 (comment)). --- Backport of Core [[bitcoin/bitcoin#17280 | PR17280]] Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D7387
… size() to data() f3b51eb Fix occurences of c_str() used with size() to data() (Wladimir J. van der Laan) Pull request description: Using `data()` better communicates the intent here. ~~Also, depending on how `c_str()` is implemented, this fixes undefined behavior: The part of the string after the first NULL character might have undefined contents (or even be inaccessible, worst case).~~ Apparently [this is no longer an issue with C++11](bitcoin#17281 (comment)). ACKs for top commit: fjahr: Code review ACK f3b51eb practicalswift: ACK f3b51eb -- diff looks correct, `data()` more idiomatic ryanofsky: Code review ACK f3b51eb. Most of these calls (including one in crypter.cpp) are passing text strings, not binary strings likely to contain `\0` and were probably safe before, but much better to avoid the possibility of bugs like this. Tree-SHA512: 842e1bdd37efc4ece2ecb87ca34962aafef0a192180051def630607e349dc9c8b4e562481fff3de474515f493b4ee3ea53b00269a801a66e625326a38dfce5b8
Merge bitcoin#19660, bitcoin#19373, bitcoin#19841, bitcoin#13862, bitcoin#13866, bitcoin#17280, bitcoin#17682 and partial bitcoin#19326, bitcoin#14978: Auxiliary Backports
Using
data()
better communicates the intent here.Also, depending on howApparently this is no longer an issue with C++11.c_str()
is implemented, this fixes undefined behavior: The part of the string after the first NULL character might have undefined contents (or even be inaccessible, worst case).