From 9dcc26c58213abb8351fbb1b2a7a1d2c667366e4 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 28 Apr 2019 19:37:23 -0400 Subject: [PATCH] Prepare for Crypto++ 8.2 release Make ConstBytePtr return non-NULL pointer --- misc.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/misc.h b/misc.h index 765a4002..7a12175f 100644 --- a/misc.h +++ b/misc.h @@ -390,6 +390,7 @@ inline size_t PtrByteDiff(const PTR pointer1, const PTR pointer2) /// \brief Pointer to the first element of a string /// \param str std::string +/// \details BytePtr returns NULL pointer for an empty string. /// \return Pointer to the first element of a string inline byte* BytePtr(std::string& str) { @@ -401,15 +402,14 @@ inline byte* BytePtr(std::string& str) return reinterpret_cast(&str[0]); } -/// \brief Pointer to the first element of a string +/// \brief Const pointer to the first element of a string /// \param str std::string -/// \details Use ConstBytePtr if Microsoft compilers match the wrong function. +/// \details ConstBytePtr returns non-NULL pointer for an empty string. /// \return Pointer to the first element of a string inline const byte* ConstBytePtr(const std::string& str) { - if (str.empty()) - return NULLPTR; - return reinterpret_cast(&str[0]); + // Use c_str() so a pointer is always available + return reinterpret_cast(str.c_str()); } /// \brief Size of a string