Skip to content

Commit 4d0ecd4

Browse files
committed
zippath.cpp: Checkpoint #2
- Fix unintialized variable issue in zippath_resolve - Eliminate one internal helper function
1 parent c161772 commit 4d0ecd4

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

src/lib/util/zippath.cpp

+12-32
Original file line numberDiff line numberDiff line change
@@ -185,31 +185,6 @@ int zippath_find_sub_path(archive_file &zipfile, std::string_view subpath, osd::
185185

186186

187187

188-
// -------------------------------------------------
189-
// parse_parent_path - parses out the parent path
190-
// -------------------------------------------------
191-
192-
void parse_parent_path(std::string_view path, std::string_view::size_type *beginpos, std::string_view::size_type *endpos)
193-
{
194-
std::string_view::size_type pos;
195-
196-
// skip over trailing path separators
197-
pos = path.find_last_not_of(PATH_SEPARATOR);
198-
199-
// return endpos
200-
if (endpos != nullptr)
201-
*endpos = pos;
202-
203-
// now skip until we find a path separator
204-
while ((pos != std::string_view::npos) && !is_path_separator(path[pos]))
205-
pos = (pos > 0) ? pos - 1 : std::string_view::npos;
206-
207-
// return beginpos
208-
if (beginpos != nullptr)
209-
*beginpos = pos;
210-
}
211-
212-
213188
// -------------------------------------------------
214189
// zippath_resolve - separates a ZIP path out into
215190
// true path and ZIP entry components
@@ -220,12 +195,11 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en
220195
newpath.clear();
221196

222197
// be conservative
223-
entry_type = osd::directory::entry::entry_type::NONE;
224198
zipfile.reset();
225199

226200
std::string apath(path);
227201
std::string apath_trimmed;
228-
osd::directory::entry::entry_type current_entry_type;
202+
osd::directory::entry::entry_type current_entry_type = osd::directory::entry::entry_type::NONE;
229203
bool went_up = false;
230204
do
231205
{
@@ -248,7 +222,6 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en
248222
else
249223
{
250224
// if we have not found the file or directory, go up
251-
current_entry_type = osd::directory::entry::entry_type::NONE;
252225
went_up = true;
253226
apath = zippath_parent(apath);
254227
}
@@ -257,7 +230,10 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en
257230

258231
// if we did not find anything, then error out
259232
if (current_entry_type == osd::directory::entry::entry_type::NONE)
233+
{
234+
entry_type = osd::directory::entry::entry_type::NONE;
260235
return osd_file::error::NOT_FOUND;
236+
}
261237

262238
// is this file a ZIP file?
263239
if ((current_entry_type == osd::directory::entry::entry_type::FILE) &&
@@ -619,13 +595,17 @@ zippath_directory::~zippath_directory()
619595

620596
std::string &zippath_parent(std::string &dst, std::string_view path)
621597
{
622-
std::string_view::size_type pos;
623-
parse_parent_path(path, &pos, nullptr);
598+
// skip over trailing path separators
599+
std::string_view::size_type pos = path.find_last_not_of(PATH_SEPARATOR);
600+
601+
// now skip until we find a path separator
602+
while ((pos != std::string_view::npos) && !is_path_separator(path[pos]))
603+
pos = (pos > 0) ? pos - 1 : std::string_view::npos;
624604

625605
if (pos != std::string_view::npos)
626-
dst = path.substr(0, pos + 1);
606+
dst = std::string(path, 0, pos + 1);
627607
else
628-
dst.clear();
608+
dst = std::string();
629609
return dst;
630610
}
631611

0 commit comments

Comments
 (0)