List Archive

Thread

Thread Index

Message

From: "Jay Freeman (saurik)" <saurik%saurik.com@localhost>
To: libzip-discuss%nih.at@localhost
Subject: [PATCH 2/3] Have _zip_add_entry work on zip_array_t instead of zip_t.
Date: Tue, 16 Aug 2016 01:54:31 -0700

---
 lib/zip_add_entry.c    | 22 +++++++++++-----------
 lib/zip_file_replace.c |  2 +-
 lib/zipint.h           |  2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/zip_add_entry.c b/lib/zip_add_entry.c
index 721fdef..577a324 100644
--- a/lib/zip_add_entry.c
+++ b/lib/zip_add_entry.c
@@ -40,13 +40,13 @@
 /* NOTE: Signed due to -1 on error.  See zip_add.c for more details. */
 
 zip_int64_t
-_zip_add_entry(zip_t *za)
+_zip_add_entry(zip_array_t *ea, zip_error_t *error)
 {
     zip_uint64_t idx;
 
-    if (za->entries.nentry+1 >= za->entries.nentry_alloc) {
+    if (ea->nentry+1 >= ea->nentry_alloc) {
        zip_entry_t *rentries;
-       zip_uint64_t nalloc = za->entries.nentry_alloc;
+       zip_uint64_t nalloc = ea->nentry_alloc;
        zip_uint64_t additional_entries = 2 * nalloc;
        zip_uint64_t realloc_size;
 
@@ -60,22 +60,22 @@ _zip_add_entry(zip_t *za)
        nalloc += additional_entries;
        realloc_size = sizeof(struct zip_entry) * (size_t)nalloc;
 
-       if (sizeof(struct zip_entry) * (size_t)za->entries.nentry_alloc > 
realloc_size) {
-           zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+       if (sizeof(struct zip_entry) * (size_t)ea->nentry_alloc > realloc_size) 
{
+           zip_error_set(error, ZIP_ER_MEMORY, 0);
            return -1;
        }
-       rentries = (zip_entry_t *)realloc(za->entries.entry, sizeof(struct 
zip_entry) * (size_t)nalloc);
+       rentries = (zip_entry_t *)realloc(ea->entry, sizeof(struct zip_entry) * 
(size_t)nalloc);
        if (!rentries) {
-           zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+           zip_error_set(error, ZIP_ER_MEMORY, 0);
            return -1;
        }
-       za->entries.entry = rentries;
-       za->entries.nentry_alloc = nalloc;
+       ea->entry = rentries;
+       ea->nentry_alloc = nalloc;
     }
 
-    idx = za->entries.nentry++;
+    idx = ea->nentry++;
 
-    _zip_entry_init(za->entries.entry+idx);
+    _zip_entry_init(ea->entry+idx);
 
     return (zip_int64_t)idx;
 }
diff --git a/lib/zip_file_replace.c b/lib/zip_file_replace.c
index 702877e..54b8177 100644
--- a/lib/zip_file_replace.c
+++ b/lib/zip_file_replace.c
@@ -72,7 +72,7 @@ _zip_file_replace(zip_t *za, zip_uint64_t idx, const char 
*name, zip_source_t *s
 
        if (i == -1) {
            /* create and use new entry, used by zip_add */
-           if ((i=_zip_add_entry(za)) < 0)
+           if ((i=_zip_add_entry(&za->entries, &za->error)) < 0)
                return -1;
        }
        idx = (zip_uint64_t)i;
diff --git a/lib/zipint.h b/lib/zipint.h
index 5d8f425..59f0e9c 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -343,7 +343,7 @@ extern const int _zip_err_type[];
 #define ZIP_IS_RDONLY(za)      ((za)->ch_flags & ZIP_AFL_RDONLY)
 
 
-zip_int64_t _zip_add_entry(zip_t *);
+zip_int64_t _zip_add_entry(zip_array_t *, zip_error_t *error);
 
 zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer);
 bool _zip_buffer_eof(zip_buffer_t *buffer);
-- 
2.6.3

Made by MHonArc.