Fix occurences of c_str() used with size() to data()

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.
This commit is contained in:
Wladimir J. van der Laan
2019-10-28 13:41:45 +01:00
parent a25945318f
commit f3b51eb935
6 changed files with 8 additions and 8 deletions

View File

@ -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)