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,8 +805,14 @@ LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, con
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()));
}
}
static void copyContextToValue(Value & v, const PathSet & context)