fix: disallow null char at the end of input

since std::string and ""_toml literal actually does not include null
char, we don't need to check if the last char is null or not
This commit is contained in:
ToruNiina
2021-12-14 22:33:58 +09:00
parent 1b5107e5e3
commit db2aa55d20
2 changed files with 1 additions and 7 deletions

View File

@@ -87,6 +87,7 @@ operator"" _toml(const char* str, std::size_t len)
::toml::detail::location loc( ::toml::detail::location loc(
std::string("TOML literal encoded in a C++ code"), std::string("TOML literal encoded in a C++ code"),
std::vector<char>(str, str + len)); std::vector<char>(str, str + len));
// literal length does not include the null character at the end.
return literal_internal_impl(std::move(loc)); return literal_internal_impl(std::move(loc));
} }

View File

@@ -2209,13 +2209,6 @@ parse(std::istream& is, const std::string& fname = "unknown file")
std::vector<char> letters(static_cast<std::size_t>(fsize)); std::vector<char> letters(static_cast<std::size_t>(fsize));
is.read(letters.data(), fsize); is.read(letters.data(), fsize);
// remove null character if exists
while(!letters.empty() && letters.back() == '\0')
{
letters.pop_back();
}
assert(letters.empty() || letters.back() != '\0');
// append LF. // append LF.
// Although TOML does not require LF at the EOF, to make parsing logic // Although TOML does not require LF at the EOF, to make parsing logic
// simpler, we "normalize" the content by adding LF if it does not exist. // simpler, we "normalize" the content by adding LF if it does not exist.