Value::mkPath: Avoid potential crash from null string_view

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

View file

@ -842,7 +842,14 @@ void Value::mkStringMove(const char * s, const PathSet & context)
void Value::mkPath(std::string_view s) void Value::mkPath(std::string_view s)
{ {
if (s.size() == 0) {
// Pathological, but better than crashing in dupStringWithLen, as
// s.data() may be null.
mkPath("");
}
else {
mkPath(dupStringWithLen(s.data(), s.size())); mkPath(dupStringWithLen(s.data(), s.size()));
}
} }