diff --git a/zipper.cpp b/zipper.cpp index b13ae34..6a183fb 100644 --- a/zipper.cpp +++ b/zipper.cpp @@ -29,7 +29,7 @@ DIR * dir_handle; dirent * dir_entry; std::ifstream file_check; std::ofstream outfile; -std::vector> zip_samples, zip_pass1; +std::vector> zip_samples; std::vector cycleN_count; char path_buf[2048]; MEMORYSTATUS mem_stat; @@ -53,7 +53,7 @@ int main(int argc, char** argv) { // definition of command line arguments abcdefghijklmnopqrstuvwxyz // abcd.f..i..lmnop.rst...... - TCLAP::CmdLine cmd("Zipper: checks different number of compression passes for 7-Zip ZIP archives.", ' ', "Zipper v1.3"); + TCLAP::CmdLine cmd("Zipper: checks different number of compression passes for 7-Zip ZIP archives.", ' ', "Zipper v1.32"); TCLAP::ValueArg cmdInputDir("i", "input-mask", "Directory with files to compress.\nRun Zipper from this directory to avoid paths inside archives. [.]", false, @@ -270,9 +270,9 @@ int main(int argc, char** argv) { if (zip_length > 0) { pass_counter = p + 1; file_check.seekg(0, file_check.beg); - zip_pass1.resize(1); - zip_pass1[0].resize(zip_length); // allocating memory - file_check.read(zip_pass1[0].data(), zip_length); // reading zip to memory + std::vector zip_pass1; + zip_pass1.resize(zip_length); // allocating memory + file_check.read(zip_pass1.data(), zip_length); // reading zip to memory file_check.close(); int t, e; bool line_start = true; @@ -286,7 +286,7 @@ int main(int argc, char** argv) { int add_index = -1; for (int c = (zip_samples.size() - t); c >= e; c--) { if (zip_samples[c].size() == static_cast(zip_length)) { - if (memcmp(zip_samples[c].data(), zip_pass1[0].data(), zip_length) == 0) { + if (memcmp(zip_samples[c].data(), zip_pass1.data(), zip_length) == 0) { add_index = c; if (old_detection) { match_counter++; @@ -294,8 +294,8 @@ int main(int argc, char** argv) { cycle_size = detect_threshold; if (match_counter == detect_threshold) { is_full = true; - zip_pass1[0].clear(); zip_pass1.clear(); + std::vector().swap(zip_pass1); goto passes_checked; } else break; @@ -316,8 +316,8 @@ int main(int argc, char** argv) { std::cout << (line_start ? "Cycle: " : ", ") << dc << "/" << cycle_size << ".\n" "Compression cycling detected, " << cycle_size << " archives. More passes should not be necessary." << std::endl; is_full = true; - zip_pass1[0].clear(); zip_pass1.clear(); + std::vector().swap(zip_pass1); goto passes_checked; wrong_cycle: if (line_start) { @@ -332,8 +332,8 @@ int main(int argc, char** argv) { } } if (add_index != -1) { - zip_pass1[0].clear(); zip_pass1.clear(); + //std::vector().swap(zip_pass1); zip_samples.push_back(zip_samples[add_index]); // same sample, referencing previous copy goto sample_added; } else { @@ -341,10 +341,10 @@ int main(int argc, char** argv) { cycle_size_max = 0; for (unsigned c = 0; c < zip_samples.size(); c++) { if (zip_samples[c].size() == static_cast(zip_length)) { - if (memcmp(zip_samples[c].data(), zip_pass1[0].data(), zip_length) == 0) { + if (memcmp(zip_samples[c].data(), zip_pass1.data(), zip_length) == 0) { //std::cout << "Matched sample, referencing previous copy." << std::endl; - zip_pass1[0].clear(); zip_pass1.clear(); + //std::vector().swap(zip_pass1); zip_samples.push_back(zip_samples[c]); goto sample_added; } @@ -352,8 +352,7 @@ int main(int argc, char** argv) { } } //std::cout << "Adding new archive." << std::endl; - zip_samples.push_back(zip_pass1[0]); - zip_pass1.clear(); + zip_samples.push_back(zip_pass1); mem_use += zip_length; if ((unsigned) zip_length < minimal_zip_length) { minimal_zip_sample = zip_samples.back(); //zip_samples[zip_samples.size() - 1];