diff options
author | Robert Hensing <robert@roberthensing.nl> | 2022-02-26 02:30:11 +0100 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2022-03-07 16:09:12 +0100 |
commit | 1b978596b575bda096a9e896a5cc3502943e5a60 (patch) | |
tree | 0f6f8682b18eb0283568e3613b254e189052e822 | |
parent | c28e2b1b2982451bafee9afede094affb08ea130 (diff) |
Value::mkString: Avoid crash from null string_view
-rw-r--r-- | src/libexpr/eval.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 2d7309738..b954e7bd9 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -805,7 +805,13 @@ LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, con void Value::mkString(std::string_view s) { - mkString(dupStringWithLen(s.data(), s.size())); + 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())); + } } |