diff options
-rw-r--r-- | libziparchive/Android.mk | 2 | ||||
-rw-r--r-- | libziparchive/zip_archive.cc | 30 |
2 files changed, 20 insertions, 12 deletions
diff --git a/libziparchive/Android.mk b/libziparchive/Android.mk index 684c635..d96bc63 100644 --- a/libziparchive/Android.mk +++ b/libziparchive/Android.mk @@ -31,7 +31,6 @@ LOCAL_MODULE:= libziparchive LOCAL_C_INCLUDES += ${includes} LOCAL_CFLAGS := -Werror -include external/libcxx/libcxx.mk include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -44,7 +43,6 @@ LOCAL_STATIC_LIBRARIES := libz libutils LOCAL_MODULE:= libziparchive-host LOCAL_CFLAGS := -Werror LOCAL_MULTILIB := both -include external/libcxx/libcxx.mk include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index cbe1b14..24088bb 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -29,7 +29,6 @@ #include <unistd.h> #include <utils/Compat.h> #include <utils/FileMap.h> -#include <vector> #include <zlib.h> #include <JNIHelp.h> // TEMP_FAILURE_RETRY may or may not be in unistd @@ -889,8 +888,23 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent, struct IterationHandle { uint32_t position; - std::vector<uint8_t> prefix; + const uint8_t* prefix; + uint16_t prefix_len; ZipArchive* archive; + + IterationHandle() : prefix(NULL), prefix_len(0) {} + + IterationHandle(const ZipEntryName& prefix_name) + : prefix_len(prefix_name.name_length) { + uint8_t* prefix_copy = new uint8_t[prefix_len]; + memcpy(reinterpret_cast<void*>(prefix_copy), prefix_name.name, + prefix_len * sizeof(uint8_t)); + prefix = prefix_copy; + } + + ~IterationHandle() { + delete [] prefix; + } }; int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, @@ -902,14 +916,10 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, return kInvalidHandle; } - IterationHandle* cookie = new IterationHandle(); + IterationHandle* cookie = + optional_prefix != NULL ? new IterationHandle(*optional_prefix) : new IterationHandle(); cookie->position = 0; cookie->archive = archive; - if (optional_prefix != NULL) { - cookie->prefix.insert(cookie->prefix.begin(), - optional_prefix->name, - optional_prefix->name + optional_prefix->name_length); - } *cookie_ptr = cookie ; return 0; @@ -956,8 +966,8 @@ int32_t Next(void* cookie, ZipEntry* data, ZipEntryName* name) { for (uint32_t i = currentOffset; i < hash_table_length; ++i) { if (hash_table[i].name != NULL && - (handle->prefix.empty() || - (memcmp(&(handle->prefix[0]), hash_table[i].name, handle->prefix.size()) == 0))) { + (handle->prefix_len == 0 || + (memcmp(handle->prefix, hash_table[i].name, handle->prefix_len) == 0))) { handle->position = (i + 1); const int error = FindEntry(archive, i, data); if (!error) { |