From 4d0ecd468dd014647dd78ec3b166a79101bcccc2 Mon Sep 17 00:00:00 2001 From: AJR Date: Fri, 8 Jan 2021 10:35:04 -0500 Subject: [PATCH] zippath.cpp: Checkpoint #2 - Fix unintialized variable issue in zippath_resolve - Eliminate one internal helper function --- src/lib/util/zippath.cpp | 44 +++++++++++----------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp index 4481e84da711e..27e5f123576b3 100644 --- a/src/lib/util/zippath.cpp +++ b/src/lib/util/zippath.cpp @@ -185,31 +185,6 @@ int zippath_find_sub_path(archive_file &zipfile, std::string_view subpath, osd:: -// ------------------------------------------------- -// parse_parent_path - parses out the parent path -// ------------------------------------------------- - -void parse_parent_path(std::string_view path, std::string_view::size_type *beginpos, std::string_view::size_type *endpos) -{ - std::string_view::size_type pos; - - // skip over trailing path separators - pos = path.find_last_not_of(PATH_SEPARATOR); - - // return endpos - if (endpos != nullptr) - *endpos = pos; - - // now skip until we find a path separator - while ((pos != std::string_view::npos) && !is_path_separator(path[pos])) - pos = (pos > 0) ? pos - 1 : std::string_view::npos; - - // return beginpos - if (beginpos != nullptr) - *beginpos = pos; -} - - // ------------------------------------------------- // zippath_resolve - separates a ZIP path out into // true path and ZIP entry components @@ -220,12 +195,11 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en newpath.clear(); // be conservative - entry_type = osd::directory::entry::entry_type::NONE; zipfile.reset(); std::string apath(path); std::string apath_trimmed; - osd::directory::entry::entry_type current_entry_type; + osd::directory::entry::entry_type current_entry_type = osd::directory::entry::entry_type::NONE; bool went_up = false; do { @@ -248,7 +222,6 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en else { // if we have not found the file or directory, go up - current_entry_type = osd::directory::entry::entry_type::NONE; went_up = true; apath = zippath_parent(apath); } @@ -257,7 +230,10 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en // if we did not find anything, then error out if (current_entry_type == osd::directory::entry::entry_type::NONE) + { + entry_type = osd::directory::entry::entry_type::NONE; return osd_file::error::NOT_FOUND; + } // is this file a ZIP file? if ((current_entry_type == osd::directory::entry::entry_type::FILE) && @@ -619,13 +595,17 @@ zippath_directory::~zippath_directory() std::string &zippath_parent(std::string &dst, std::string_view path) { - std::string_view::size_type pos; - parse_parent_path(path, &pos, nullptr); + // skip over trailing path separators + std::string_view::size_type pos = path.find_last_not_of(PATH_SEPARATOR); + + // now skip until we find a path separator + while ((pos != std::string_view::npos) && !is_path_separator(path[pos])) + pos = (pos > 0) ? pos - 1 : std::string_view::npos; if (pos != std::string_view::npos) - dst = path.substr(0, pos + 1); + dst = std::string(path, 0, pos + 1); else - dst.clear(); + dst = std::string(); return dst; }