diff --git a/src/util.cc b/src/util.cc index 544b547b29..54b1041501 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1552,13 +1552,13 @@ TEST_CASE("util normalize_path") CHECK(normalize_path("zeek/../..") == ".."); } -string normalize_path(const string& path) +string normalize_path(const std::string_view path) { size_t n; vector components, final_components; string new_path; - if ( path[0] == '/' ) + if ( !path.empty() && path[0] == '/' ) new_path = "/"; tokenize_string(path, "/", &components); diff --git a/src/util.h b/src/util.h index 9442357e0b..b2b346f727 100644 --- a/src/util.h +++ b/src/util.h @@ -344,7 +344,7 @@ std::string flatten_script_name(const std::string& name, * @param path A filesystem path. * @return A canonical/shortened version of \a path. */ -std::string normalize_path(const std::string& path); +std::string normalize_path(std::string_view path); /** * Strip the ZEEKPATH component from a path.