From a42f896351509219c8c9df0d6368f84b77a9a0d3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 28 Jul 2022 02:39:15 +0100 Subject: Don't pass potentially NULL PATH env to string_view --- slicer/tool/slicer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slicer/tool/slicer.cpp b/slicer/tool/slicer.cpp index 1a83519..a4439cb 100644 --- a/slicer/tool/slicer.cpp +++ b/slicer/tool/slicer.cpp @@ -29,7 +29,12 @@ defaultPostProcessor() constexpr std::array, 1> pps {{ {"clang-format", "-i"}, }}; - const std::string_view path {getenv("PATH")}; + const auto path {[]() -> std::string_view { + if (auto p = getenv("PATH")) { + return p; + } + return ""; + }()}; const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal())); for (const auto & [cmd, opts] : pps) { for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) { -- cgit v1.2.3