Avoid undefined behaviour const_casting std::string c_str()

Use non-const data() instead

See: #224
This commit is contained in:
Jonathan G Rennison
2021-03-11 01:08:33 +00:00
parent 63d1fe4419
commit 4361a6dbf4
10 changed files with 18 additions and 17 deletions

View File

@@ -14,7 +14,7 @@
static inline void str_validate_inplace(std::string &str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK)
{
if (str.empty()) return;
char *buf = const_cast<char *>(str.c_str());
char *buf = str.data();
str.resize(str_validate(buf, buf + str.size(), settings) - buf);
}