Skip to content

Commit

Permalink
archive/zip: Use vector instead of new char[] for temp file buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ahodesuka committed Dec 3, 2017
1 parent 0f6c47e commit 54993bc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/archive/zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,20 @@ bool Zip::extract(const std::string &file) const
break;
}

char *buf = new char[st.size];
std::vector<char> buf(st.size);
int bufSize;
if ((bufSize = zip_fread(zfile, buf, st.size)) != -1)
if ((bufSize = zip_fread(zfile, &buf[0], st.size)) != -1)
{
try
{
Glib::file_set_contents(fPath, buf, bufSize);
Glib::file_set_contents(fPath, buf.data(), bufSize);
}
catch(const Glib::FileError &ex)
{
std::cerr << "Glib::file_set_contents: " << ex.what() << std::endl;
}
}

delete[] buf;
zip_fclose(zfile);
found = true;
break;
Expand Down

0 comments on commit 54993bc

Please sign in to comment.