diff --git a/src/BinaryDict.cpp b/src/BinaryDict.cpp index 6357b2547..9302932d7 100644 --- a/src/BinaryDict.cpp +++ b/src/BinaryDict.cpp @@ -168,28 +168,30 @@ void BinaryDict::ConstructBuffer(std::string& keyBuf, // Write keys and values to buffers keyBuf.resize(keyTotalLength, '\0'); valueBuf.resize(valueTotalLength, '\0'); - char* pKeyBuffer = const_cast(keyBuf.c_str()); - char* pValueBuffer = const_cast(valueBuf.c_str()); + char* pKeyBuffer = keyBuf.data(); + char* pValueBuffer = valueBuf.data(); for (const std::unique_ptr& entry : *lexicon) { - strcpy(pKeyBuffer, entry->Key().c_str()); - keyOffset.push_back(pKeyBuffer - keyBuf.c_str()); - pKeyBuffer += entry->KeyLength() + 1; + const std::string& key = entry->Key(); + strcpy(pKeyBuffer, key.c_str()); + keyOffset.push_back(pKeyBuffer - keyBuf.data()); + pKeyBuffer += key.length() + 1; if (entry->NumValues() == 1) { const auto* svEntry = static_cast(entry.get()); - strcpy(pValueBuffer, svEntry->Value().c_str()); - valueOffset.push_back(pValueBuffer - valueBuf.c_str()); - pValueBuffer += svEntry->Value().length() + 1; + const std::string& val = svEntry->Value(); + strcpy(pValueBuffer, val.c_str()); + valueOffset.push_back(pValueBuffer - valueBuf.data()); + pValueBuffer += val.length() + 1; } else { const auto* mvEntry = static_cast(entry.get()); for (const auto& value : mvEntry->Values()) { strcpy(pValueBuffer, value.c_str()); - valueOffset.push_back(pValueBuffer - valueBuf.c_str()); + valueOffset.push_back(pValueBuffer - valueBuf.data()); pValueBuffer += value.length() + 1; } } } - assert(keyBuf.c_str() + keyTotalLength == pKeyBuffer); - assert(valueBuf.c_str() + valueTotalLength == pValueBuffer); + assert(keyBuf.data() + keyTotalLength == pKeyBuffer); + assert(valueBuf.data() + valueTotalLength == pValueBuffer); } diff --git a/src/SerializedValues.cpp b/src/SerializedValues.cpp index 1a96100b0..3aceba414 100644 --- a/src/SerializedValues.cpp +++ b/src/SerializedValues.cpp @@ -123,7 +123,7 @@ void SerializedValues::ConstructBuffer(std::string* valueBuffer, } // Write values to the buffer. valueBuffer->resize(*valueTotalLength, '\0'); - char* pValueBuffer = const_cast(valueBuffer->c_str()); + char* pValueBuffer = valueBuffer->data(); for (const std::unique_ptr& entry : *lexicon) { for (const auto& value : entry->Values()) { strcpy(pValueBuffer, value.c_str()); @@ -131,5 +131,5 @@ void SerializedValues::ConstructBuffer(std::string* valueBuffer, pValueBuffer += value.length() + 1; } } - assert(valueBuffer->c_str() + *valueTotalLength == pValueBuffer); + assert(valueBuffer->data() + *valueTotalLength == pValueBuffer); } diff --git a/src/UTF8Util.hpp b/src/UTF8Util.hpp index 6babd3674..f1db415b6 100644 --- a/src/UTF8Util.hpp +++ b/src/UTF8Util.hpp @@ -158,7 +158,7 @@ class OPENCC_EXPORT UTF8Util { static std::string FromSubstr(const char* str, size_t length) { std::string newStr; newStr.resize(length); - strncpy(const_cast(newStr.c_str()), str, length); + strncpy(newStr.data(), str, length); return newStr; } diff --git a/src/tools/CommandLine.cpp b/src/tools/CommandLine.cpp index bfbd64b03..96c0fa41a 100644 --- a/src/tools/CommandLine.cpp +++ b/src/tools/CommandLine.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#include #include #ifdef _WIN32