Value::mkString: Avoid crash from null string_view

This commit is contained in:
Robert Hensing 2022-02-26 02:30:11 +01:00
parent c28e2b1b29
commit 1b978596b5

View file

@ -805,7 +805,13 @@ LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, con
void Value::mkString(std::string_view s) void Value::mkString(std::string_view s)
{ {
if (s.size() == 0) {
// s.data() may not be valid and we don't need to allocate.
mkString("");
}
else {
mkString(dupStringWithLen(s.data(), s.size())); mkString(dupStringWithLen(s.data(), s.size()));
}
} }