mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
Merge #17280: refactor: Change occurences of c_str() used with size() to data()
f3b51eb935Fix 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](https://github.com/bitcoin/bitcoin/pull/17281#discussion_r339742128). ACKs for top commit: fjahr: Code review ACKf3b51ebpracticalswift: ACKf3b51eb935-- diff looks correct, `data()` more idiomatic ryanofsky: Code review ACKf3b51eb935. 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
This commit is contained in:
@@ -138,7 +138,7 @@ std::string EncodeBase64(const unsigned char* pch, size_t len)
|
||||
|
||||
std::string EncodeBase64(const std::string& str)
|
||||
{
|
||||
return EncodeBase64((const unsigned char*)str.c_str(), str.size());
|
||||
return EncodeBase64((const unsigned char*)str.data(), str.size());
|
||||
}
|
||||
|
||||
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
|
||||
@@ -207,7 +207,7 @@ std::string EncodeBase32(const unsigned char* pch, size_t len)
|
||||
|
||||
std::string EncodeBase32(const std::string& str)
|
||||
{
|
||||
return EncodeBase32((const unsigned char*)str.c_str(), str.size());
|
||||
return EncodeBase32((const unsigned char*)str.data(), str.size());
|
||||
}
|
||||
|
||||
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
|
||||
|
||||
Reference in New Issue
Block a user