List Archive

Thread

Thread Index

Message

From: "Jay Freeman (saurik)" <saurik%saurik.com@localhost>
To: libzip-discuss%nih.at@localhost
Subject: [PATCH 1/3] Use zip_array_t to unify zip_t and zip_cdir_t.
Date: Tue, 16 Aug 2016 01:54:30 -0700

---
 lib/zip_add_entry.c                    | 16 +++++++-------
 lib/zip_close.c                        | 14 ++++++------
 lib/zip_delete.c                       |  4 ++--
 lib/zip_dirent.c                       | 28 ++++++++++++------------
 lib/zip_discard.c                      |  8 +++----
 lib/zip_extra_field.c                  |  4 ++--
 lib/zip_extra_field_api.c              | 10 ++++-----
 lib/zip_file_get_offset.c              |  2 +-
 lib/zip_file_rename.c                  |  2 +-
 lib/zip_file_replace.c                 | 24 ++++++++++----------
 lib/zip_file_set_comment.c             |  2 +-
 lib/zip_file_set_external_attributes.c |  2 +-
 lib/zip_file_set_mtime.c               |  2 +-
 lib/zip_get_num_entries.c              |  6 ++---
 lib/zip_get_num_files.c                |  4 ++--
 lib/zip_name_locate.c                  |  2 +-
 lib/zip_new.c                          |  4 ++--
 lib/zip_open.c                         | 40 +++++++++++++++++-----------------
 lib/zip_set_file_compression.c         |  4 ++--
 lib/zip_set_name.c                     |  4 ++--
 lib/zip_source_zip_new.c               |  4 ++--
 lib/zip_stat_index.c                   |  4 ++--
 lib/zip_unchange.c                     | 12 +++++-----
 lib/zip_unchange_all.c                 |  2 +-
 lib/zipint.h                           | 15 ++++++++-----
 25 files changed, 111 insertions(+), 108 deletions(-)

diff --git a/lib/zip_add_entry.c b/lib/zip_add_entry.c
index 9a9465c..721fdef 100644
--- a/lib/zip_add_entry.c
+++ b/lib/zip_add_entry.c
@@ -44,9 +44,9 @@ _zip_add_entry(zip_t *za)
 {
     zip_uint64_t idx;
 
-    if (za->nentry+1 >= za->nentry_alloc) {
+    if (za->entries.nentry+1 >= za->entries.nentry_alloc) {
        zip_entry_t *rentries;
-       zip_uint64_t nalloc = za->nentry_alloc;
+       zip_uint64_t nalloc = za->entries.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->nentry_alloc > realloc_size) 
{
+       if (sizeof(struct zip_entry) * (size_t)za->entries.nentry_alloc > 
realloc_size) {
            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
            return -1;
        }
-       rentries = (zip_entry_t *)realloc(za->entry, sizeof(struct zip_entry) * 
(size_t)nalloc);
+       rentries = (zip_entry_t *)realloc(za->entries.entry, sizeof(struct 
zip_entry) * (size_t)nalloc);
        if (!rentries) {
            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
            return -1;
        }
-       za->entry = rentries;
-       za->nentry_alloc = nalloc;
+       za->entries.entry = rentries;
+       za->entries.nentry_alloc = nalloc;
     }
 
-    idx = za->nentry++;
+    idx = za->entries.nentry++;
 
-    _zip_entry_init(za->entry+idx);
+    _zip_entry_init(za->entries.entry+idx);
 
     return (zip_int64_t)idx;
 }
diff --git a/lib/zip_close.c b/lib/zip_close.c
index b5eca67..2d71b7b 100644
--- a/lib/zip_close.c
+++ b/lib/zip_close.c
@@ -91,7 +91,7 @@ zip_close(zip_t *za)
        return 0;
     }
 
-    if (survivors > za->nentry) {
+    if (survivors > za->entries.nentry) {
         zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
         return -1;
     }
@@ -100,8 +100,8 @@ zip_close(zip_t *za)
        return -1;
 
     /* create list of files with index into original archive  */
-    for (i=j=0; i<za->nentry; i++) {
-       if (za->entry[i].deleted)
+    for (i=j=0; i<za->entries.nentry; i++) {
+       if (za->entries.entry[i].deleted)
            continue;
 
         if (j >= survivors) {
@@ -132,7 +132,7 @@ zip_close(zip_t *za)
        zip_dirent_t *de;
 
        i = filelist[j].idx;
-       entry = za->entry+i;
+       entry = za->entries.entry+i;
 
        new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, 
ZIP_DIRENT_COMP_METHOD));
 
@@ -478,10 +478,10 @@ _zip_changed(const zip_t *za, zip_uint64_t *survivorsp)
     if (za->comment_changed || za->ch_flags != za->flags)
        changed = 1;
 
-    for (i=0; i<za->nentry; i++) {
-       if (za->entry[i].deleted || za->entry[i].source || 
(za->entry[i].changes && za->entry[i].changes->changed != 0))
+    for (i=0; i<za->entries.nentry; i++) {
+       if (za->entries.entry[i].deleted || za->entries.entry[i].source || 
(za->entries.entry[i].changes && za->entries.entry[i].changes->changed != 0))
            changed = 1;
-       if (!za->entry[i].deleted)
+       if (!za->entries.entry[i].deleted)
            survivors++;
     }
 
diff --git a/lib/zip_delete.c b/lib/zip_delete.c
index 34520b0..c057cb9 100644
--- a/lib/zip_delete.c
+++ b/lib/zip_delete.c
@@ -40,7 +40,7 @@ zip_delete(zip_t *za, zip_uint64_t idx)
 {
     const char *name;
 
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
@@ -63,7 +63,7 @@ zip_delete(zip_t *za, zip_uint64_t idx)
     if (_zip_unchange(za, idx, 1) != 0)
        return -1;
 
-    za->entry[idx].deleted = 1;
+    za->entries.entry[idx].deleted = 1;
 
     return 0;
 }
diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c
index 74f8988..87a34c2 100644
--- a/lib/zip_dirent.c
+++ b/lib/zip_dirent.c
@@ -54,9 +54,9 @@ _zip_cdir_free(zip_cdir_t *cd)
     if (!cd)
        return;
 
-    for (i=0; i<cd->nentry; i++)
-       _zip_entry_finalize(cd->entry+i);
-    free(cd->entry);
+    for (i=0; i<cd->entries.nentry; i++)
+       _zip_entry_finalize(cd->entries.entry+i);
+    free(cd->entries.entry);
     _zip_string_free(cd->comment);
     free(cd);
 }
@@ -74,17 +74,17 @@ _zip_cdir_new(zip_uint64_t nentry, zip_error_t *error)
     }
 
     if (nentry == 0)
-       cd->entry = NULL;
-    else if ((nentry > SIZE_MAX/sizeof(*(cd->entry))) || 
(cd->entry=(zip_entry_t *)malloc(sizeof(*(cd->entry))*(size_t)nentry)) == NULL) 
{
+       cd->entries.entry = NULL;
+    else if ((nentry > SIZE_MAX/sizeof(*(cd->entries.entry))) || 
(cd->entries.entry=(zip_entry_t 
*)malloc(sizeof(*(cd->entries.entry))*(size_t)nentry)) == NULL) {
        zip_error_set(error, ZIP_ER_MEMORY, 0);
        free(cd);
        return NULL;
     }
 
     for (i=0; i<nentry; i++)
-       _zip_entry_init(cd->entry+i);
+       _zip_entry_init(cd->entries.entry+i);
 
-    cd->nentry = cd->nentry_alloc = nentry;
+    cd->entries.nentry = cd->entries.nentry_alloc = nentry;
     cd->size = cd->offset = 0;
     cd->comment = NULL;
 
@@ -113,7 +113,7 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, 
zip_uint64_t survivor
     is_zip64 = false;
 
     for (i=0; i<survivors; i++) {
-       zip_entry_t *entry = za->entry+filelist[i].idx;
+       zip_entry_t *entry = za->entries.entry+filelist[i].idx;
 
        if ((ret=_zip_dirent_write(za, entry->changes ? entry->changes : 
entry->orig, ZIP_FL_CENTRAL)) < 0)
            return -1;
@@ -873,24 +873,24 @@ _zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t 
flags, zip_error_t *err
     if (error == NULL)
        error = &za->error;
 
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
        zip_error_set(error, ZIP_ER_INVAL, 0);
        return NULL;
     }
 
-    if ((flags & ZIP_FL_UNCHANGED) || za->entry[idx].changes == NULL) {
-       if (za->entry[idx].orig == NULL) {
+    if ((flags & ZIP_FL_UNCHANGED) || za->entries.entry[idx].changes == NULL) {
+       if (za->entries.entry[idx].orig == NULL) {
            zip_error_set(error, ZIP_ER_INVAL, 0);
            return NULL;
        }
-       if (za->entry[idx].deleted && (flags & ZIP_FL_UNCHANGED) == 0) {
+       if (za->entries.entry[idx].deleted && (flags & ZIP_FL_UNCHANGED) == 0) {
            zip_error_set(error, ZIP_ER_DELETED, 0);
            return NULL;
        }
-       return za->entry[idx].orig;
+       return za->entries.entry[idx].orig;
     }
     else
-       return za->entry[idx].changes;
+       return za->entries.entry[idx].changes;
 }
 
 
diff --git a/lib/zip_discard.c b/lib/zip_discard.c
index 1876c84..a503143 100644
--- a/lib/zip_discard.c
+++ b/lib/zip_discard.c
@@ -60,10 +60,10 @@ zip_discard(zip_t *za)
 
     _zip_hash_free(za->names);
 
-    if (za->entry) {
-       for (i=0; i<za->nentry; i++)
-           _zip_entry_finalize(za->entry+i);
-       free(za->entry);
+    if (za->entries.entry) {
+       for (i=0; i<za->entries.nentry; i++)
+           _zip_entry_finalize(za->entries.entry+i);
+       free(za->entries.entry);
     }
 
     for (i=0; i<za->nopen_source; i++) {
diff --git a/lib/zip_extra_field.c b/lib/zip_extra_field.c
index 0350478..708276c 100644
--- a/lib/zip_extra_field.c
+++ b/lib/zip_extra_field.c
@@ -366,12 +366,12 @@ _zip_read_local_ef(zip_t *za, zip_uint64_t idx)
     zip_buffer_t *buffer;
     zip_uint16_t fname_len, ef_len;
 
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
 
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
 
     if (e->orig == NULL || e->orig->local_extra_fields_read)
        return 0;
diff --git a/lib/zip_extra_field_api.c b/lib/zip_extra_field_api.c
index ed93944..8308990 100644
--- a/lib/zip_extra_field_api.c
+++ b/lib/zip_extra_field_api.c
@@ -61,7 +61,7 @@ zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, 
zip_uint16_t ef_idx, zi
     if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
         return -1;
     
-    de = za->entry[idx].changes;
+    de = za->entries.entry[idx].changes;
     
     de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, 
ZIP_EXTRA_FIELD_ALL, ef_idx, flags);
     return 0;
@@ -94,7 +94,7 @@ zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t 
idx, zip_uint16_t ef_i
     if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
         return -1;
     
-    de = za->entry[idx].changes;
+    de = za->entries.entry[idx].changes;
 
     de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ef_id, ef_idx, 
flags);
     return 0;
@@ -253,7 +253,7 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, 
zip_uint16_t ef_id, zip_ui
     if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
         return -1;
     
-    de = za->entry[idx].changes;
+    de = za->entries.entry[idx].changes;
 
     ef = de->extra_fields;
     ef_prev = NULL;
@@ -333,12 +333,12 @@ _zip_file_extra_field_prepare_for_change(zip_t *za, 
zip_uint64_t idx)
 {
     zip_entry_t *e;
     
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
         zip_error_set(&za->error, ZIP_ER_INVAL, 0);
         return -1;
     }
     
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
     
     if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD))
         return 0;
diff --git a/lib/zip_file_get_offset.c b/lib/zip_file_get_offset.c
index 0257b04..14e4515 100644
--- a/lib/zip_file_get_offset.c
+++ b/lib/zip_file_get_offset.c
@@ -53,7 +53,7 @@ _zip_file_get_offset(const zip_t *za, zip_uint64_t idx, 
zip_error_t *error)
     zip_uint64_t offset;
     zip_int32_t size;
 
-    offset = za->entry[idx].orig->offset;
+    offset = za->entries.entry[idx].orig->offset;
 
     if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
        _zip_error_set_from_source(error, za->src);
diff --git a/lib/zip_file_rename.c b/lib/zip_file_rename.c
index 4400938..233cda6 100644
--- a/lib/zip_file_rename.c
+++ b/lib/zip_file_rename.c
@@ -43,7 +43,7 @@ zip_file_rename(zip_t *za, zip_uint64_t idx, const char 
*name, zip_flags_t flags
     const char *old_name;
     int old_is_dir, new_is_dir;
     
-    if (idx >= za->nentry || (name != NULL && strlen(name) > ZIP_UINT16_MAX)) {
+    if (idx >= za->entries.nentry || (name != NULL && strlen(name) > 
ZIP_UINT16_MAX)) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
diff --git a/lib/zip_file_replace.c b/lib/zip_file_replace.c
index e430efa..702877e 100644
--- a/lib/zip_file_replace.c
+++ b/lib/zip_file_replace.c
@@ -38,7 +38,7 @@
 ZIP_EXTERN int
 zip_file_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source, 
zip_flags_t flags)
 {
-    if (idx >= za->nentry || source == NULL) {
+    if (idx >= za->entries.nentry || source == NULL) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
@@ -63,7 +63,7 @@ _zip_file_replace(zip_t *za, zip_uint64_t idx, const char 
*name, zip_source_t *s
        return -1;
     }
 
-    za_nentry_prev = za->nentry;
+    za_nentry_prev = za->entries.nentry;
     if (idx == ZIP_UINT64_MAX) {
        zip_int64_t i = -1;
        
@@ -79,30 +79,30 @@ _zip_file_replace(zip_t *za, zip_uint64_t idx, const char 
*name, zip_source_t *s
     }
     
     if (name && _zip_set_name(za, idx, name, flags) != 0) {
-       if (za->nentry != za_nentry_prev) {
-           _zip_entry_finalize(za->entry+idx);
-           za->nentry = za_nentry_prev;
+       if (za->entries.nentry != za_nentry_prev) {
+           _zip_entry_finalize(za->entries.entry+idx);
+           za->entries.nentry = za_nentry_prev;
        }
        return -1;
     }
 
     /* does not change any name related data, so we can do it here;
      * needed for a double add of the same file name */
-    _zip_unchange_data(za->entry+idx);
+    _zip_unchange_data(za->entries.entry+idx);
 
-    if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || 
(za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) {
-        if (za->entry[idx].changes == NULL) {
-            if 
((za->entry[idx].changes=_zip_dirent_clone(za->entry[idx].orig)) == NULL) {
+    if (za->entries.entry[idx].orig != NULL && (za->entries.entry[idx].changes 
== NULL || (za->entries.entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) 
== 0)) {
+        if (za->entries.entry[idx].changes == NULL) {
+            if 
((za->entries.entry[idx].changes=_zip_dirent_clone(za->entries.entry[idx].orig))
 == NULL) {
                 zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
                 return -1;
             }
         }
 
-        za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT;
-        za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD;
+        za->entries.entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT;
+        za->entries.entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD;
     }
        
-    za->entry[idx].source = source;
+    za->entries.entry[idx].source = source;
 
     return (zip_int64_t)idx;
 }
diff --git a/lib/zip_file_set_comment.c b/lib/zip_file_set_comment.c
index e455fbd..e52880e 100644
--- a/lib/zip_file_set_comment.c
+++ b/lib/zip_file_set_comment.c
@@ -67,7 +67,7 @@ zip_file_set_comment(zip_t *za, zip_uint64_t idx,
     else
        cstr = NULL;
 
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
 
     if (e->changes) {
        _zip_string_free(e->changes->comment);
diff --git a/lib/zip_file_set_external_attributes.c 
b/lib/zip_file_set_external_attributes.c
index b772c31..a360dad 100644
--- a/lib/zip_file_set_external_attributes.c
+++ b/lib/zip_file_set_external_attributes.c
@@ -49,7 +49,7 @@ zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, 
zip_flags_t flags,
        return -1;
     }
 
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
 
     unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby>>8) : 
(zip_uint8_t)ZIP_OPSYS_DEFAULT);
     unchanged_attributes = e->orig ? e->orig->ext_attrib : 
ZIP_EXT_ATTRIB_DEFAULT;
diff --git a/lib/zip_file_set_mtime.c b/lib/zip_file_set_mtime.c
index 0cdd31a..11203d0 100644
--- a/lib/zip_file_set_mtime.c
+++ b/lib/zip_file_set_mtime.c
@@ -46,7 +46,7 @@ ZIP_EXTERN int zip_file_set_mtime(zip_t *za, zip_uint64_t 
idx, time_t mtime, zip
         return -1;
     }
     
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
 
     changed = e->orig == NULL || mtime != e->orig->last_mod;
     
diff --git a/lib/zip_get_num_entries.c b/lib/zip_get_num_entries.c
index c8644a4..40de569 100644
--- a/lib/zip_get_num_entries.c
+++ b/lib/zip_get_num_entries.c
@@ -44,10 +44,10 @@ zip_get_num_entries(zip_t *za, zip_flags_t flags)
        return -1;
 
     if (flags & ZIP_FL_UNCHANGED) {
-       n = za->nentry;
-       while (n>0 && za->entry[n-1].orig == NULL)
+       n = za->entries.nentry;
+       while (n>0 && za->entries.entry[n-1].orig == NULL)
            --n;
        return (zip_int64_t)n;
     }
-    return (zip_int64_t)za->nentry;
+    return (zip_int64_t)za->entries.nentry;
 }
diff --git a/lib/zip_get_num_files.c b/lib/zip_get_num_files.c
index cf96353..487c3da 100644
--- a/lib/zip_get_num_files.c
+++ b/lib/zip_get_num_files.c
@@ -43,10 +43,10 @@ zip_get_num_files(zip_t *za)
     if (za == NULL)
        return -1;
 
-    if (za->nentry > INT_MAX) {
+    if (za->entries.nentry > INT_MAX) {
        zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0);
        return -1;
     }
 
-    return (int)za->nentry;
+    return (int)za->entries.nentry;
 }
diff --git a/lib/zip_name_locate.c b/lib/zip_name_locate.c
index 50ca40b..163152f 100644
--- a/lib/zip_name_locate.c
+++ b/lib/zip_name_locate.c
@@ -66,7 +66,7 @@ _zip_name_locate(zip_t *za, const char *fname, zip_flags_t 
flags, zip_error_t *e
        /* can't use hash table */
        cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
 
-       for (i=0; i<za->nentry; i++) {
+       for (i=0; i<za->entries.nentry; i++) {
            fn = _zip_get_name(za, i, flags, error);
            
            /* newly added (partially filled) entry or error */
diff --git a/lib/zip_new.c b/lib/zip_new.c
index 562dd76..623fdd2 100644
--- a/lib/zip_new.c
+++ b/lib/zip_new.c
@@ -64,8 +64,8 @@ _zip_new(zip_error_t *error)
     za->default_password = NULL;
     za->comment_orig = za->comment_changes = NULL;
     za->comment_changed = 0;
-    za->nentry = za->nentry_alloc = 0;
-    za->entry = NULL;
+    za->entries.nentry = za->entries.nentry_alloc = 0;
+    za->entries.entry = NULL;
     za->nopen_source = za->nopen_source_alloc = 0;
     za->open_source = NULL;
     za->tempdir = NULL;
diff --git a/lib/zip_open.c b/lib/zip_open.c
index d6209ee..62ba35a 100644
--- a/lib/zip_open.c
+++ b/lib/zip_open.c
@@ -218,15 +218,15 @@ _zip_open(zip_source_t *src, unsigned int flags, 
zip_error_t *error)
        return NULL;
     }
 
-    za->entry = cdir->entry;
-    za->nentry = cdir->nentry;
-    za->nentry_alloc = cdir->nentry_alloc;
+    za->entries.entry = cdir->entries.entry;
+    za->entries.nentry = cdir->entries.nentry;
+    za->entries.nentry_alloc = cdir->entries.nentry_alloc;
     za->comment_orig = cdir->comment;
 
     free(cdir);
 
-    for (idx = 0; idx < za->nentry; idx++) {
-       const zip_uint8_t *name = 
_zip_string_get(za->entry[idx].orig->filename, NULL, 0, error);
+    for (idx = 0; idx < za->entries.nentry; idx++) {
+       const zip_uint8_t *name = 
_zip_string_get(za->entries.entry[idx].orig->filename, NULL, 0, error);
        if (name == NULL) {
                /* keep src so discard does not get rid of it */
                zip_source_keep(src);
@@ -370,9 +370,9 @@ _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, 
zip_uint64_t buf_offset, zip_err
 
     left = (zip_uint64_t)cd->size;
     i=0;
-    while (i<cd->nentry && left > 0) {
+    while (i<cd->entries.nentry && left > 0) {
         zip_int64_t entry_size;
-       if ((cd->entry[i].orig=_zip_dirent_new()) == NULL || (entry_size = 
_zip_dirent_read(cd->entry[i].orig, za->src, cd_buffer, false, error)) < 0) {
+       if ((cd->entries.entry[i].orig=_zip_dirent_new()) == NULL || 
(entry_size = _zip_dirent_read(cd->entries.entry[i].orig, za->src, cd_buffer, 
false, error)) < 0) {
            _zip_cdir_free(cd);
             _zip_buffer_free(cd_buffer);
            return NULL;
@@ -381,7 +381,7 @@ _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, 
zip_uint64_t buf_offset, zip_err
         left -= (zip_uint64_t)entry_size;
     }
     
-    if (i != cd->nentry) {
+    if (i != cd->entries.nentry) {
         zip_error_set(error, ZIP_ER_INCONS, 0);
         _zip_buffer_free(cd_buffer);
         _zip_cdir_free(cd);
@@ -433,23 +433,23 @@ _zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t 
*error)
     struct zip_dirent temp;
 
     _zip_dirent_init(&temp);
-    if (cd->nentry) {
-       max = cd->entry[0].orig->offset;
-       min = cd->entry[0].orig->offset;
+    if (cd->entries.nentry) {
+       max = cd->entries.entry[0].orig->offset;
+       min = cd->entries.entry[0].orig->offset;
     }
     else
        min = max = 0;
 
-    for (i=0; i<cd->nentry; i++) {
-       if (cd->entry[i].orig->offset < min)
-           min = cd->entry[i].orig->offset;
+    for (i=0; i<cd->entries.nentry; i++) {
+       if (cd->entries.entry[i].orig->offset < min)
+           min = cd->entries.entry[i].orig->offset;
        if (min > (zip_uint64_t)cd->offset) {
            zip_error_set(error, ZIP_ER_NOZIP, 0);
            return -1;
        }
        
-       j = cd->entry[i].orig->offset + cd->entry[i].orig->comp_size
-           + _zip_string_length(cd->entry[i].orig->filename) + LENTRYSIZE;
+       j = cd->entries.entry[i].orig->offset + 
cd->entries.entry[i].orig->comp_size
+           + _zip_string_length(cd->entries.entry[i].orig->filename) + 
LENTRYSIZE;
        if (j > max)
            max = j;
        if (max > (zip_uint64_t)cd->offset) {
@@ -457,7 +457,7 @@ _zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t 
*error)
            return -1;
        }
        
-        if (zip_source_seek(za->src, (zip_int64_t)cd->entry[i].orig->offset, 
SEEK_SET) < 0) {
+        if (zip_source_seek(za->src, 
(zip_int64_t)cd->entries.entry[i].orig->offset, SEEK_SET) < 0) {
             _zip_error_set_from_source(error, za->src);
             return -1;
        }
@@ -467,14 +467,14 @@ _zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t 
*error)
            return -1;
        }
        
-       if (_zip_headercomp(cd->entry[i].orig, &temp) != 0) {
+       if (_zip_headercomp(cd->entries.entry[i].orig, &temp) != 0) {
            zip_error_set(error, ZIP_ER_INCONS, 0);
            _zip_dirent_finalize(&temp);
            return -1;
        }
        
-       cd->entry[i].orig->extra_fields = 
_zip_ef_merge(cd->entry[i].orig->extra_fields, temp.extra_fields);
-       cd->entry[i].orig->local_extra_fields_read = 1;
+       cd->entries.entry[i].orig->extra_fields = 
_zip_ef_merge(cd->entries.entry[i].orig->extra_fields, temp.extra_fields);
+       cd->entries.entry[i].orig->local_extra_fields_read = 1;
        temp.extra_fields = NULL;
        
        _zip_dirent_finalize(&temp);
diff --git a/lib/zip_set_file_compression.c b/lib/zip_set_file_compression.c
index 7bb0bf9..a38d32a 100644
--- a/lib/zip_set_file_compression.c
+++ b/lib/zip_set_file_compression.c
@@ -41,7 +41,7 @@ zip_set_file_compression(zip_t *za, zip_uint64_t idx, 
zip_int32_t method, zip_ui
     zip_entry_t *e;
     zip_int32_t old_method;
 
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
@@ -56,7 +56,7 @@ zip_set_file_compression(zip_t *za, zip_uint64_t idx, 
zip_int32_t method, zip_ui
        return -1;
     }
 
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
     
     old_method = (e->orig == NULL ? ZIP_CM_DEFAULT : e->orig->comp_method);
     
diff --git a/lib/zip_set_name.c b/lib/zip_set_name.c
index 2a46143..d444b80 100644
--- a/lib/zip_set_name.c
+++ b/lib/zip_set_name.c
@@ -48,7 +48,7 @@ _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, 
zip_flags_t flags)
     const zip_uint8_t *old_name, *new_name;
     zip_string_t *old_str;
 
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
@@ -81,7 +81,7 @@ _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, 
zip_flags_t flags)
        return 0;
     }
 
-    e = za->entry+idx;
+    e = za->entries.entry+idx;
 
     if (e->orig)
        same_as_orig = _zip_string_equal(e->orig->filename, str);
diff --git a/lib/zip_source_zip_new.c b/lib/zip_source_zip_new.c
index 40f1195..712acbe 100644
--- a/lib/zip_source_zip_new.c
+++ b/lib/zip_source_zip_new.c
@@ -49,13 +49,13 @@ _zip_source_zip_new(zip_t *za, zip_t *srcza, zip_uint64_t 
srcidx, zip_flags_t fl
     if (za == NULL)
        return NULL;
 
-    if (srcza == NULL || srcidx >= srcza->nentry) {
+    if (srcza == NULL || srcidx >= srcza->entries.nentry) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return NULL;
     }
 
     if ((flags & ZIP_FL_UNCHANGED) == 0
-       && (ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx) || 
srcza->entry[srcidx].deleted)) {
+       && (ZIP_ENTRY_DATA_CHANGED(srcza->entries.entry+srcidx) || 
srcza->entries.entry[srcidx].deleted)) {
        zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
        return NULL;
     }
diff --git a/lib/zip_stat_index.c b/lib/zip_stat_index.c
index 601e3f7..44c191c 100644
--- a/lib/zip_stat_index.c
+++ b/lib/zip_stat_index.c
@@ -50,8 +50,8 @@ zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t 
flags,
     
 
     if ((flags & ZIP_FL_UNCHANGED) == 0
-       && ZIP_ENTRY_DATA_CHANGED(za->entry+index)) {
-       if (zip_source_stat(za->entry[index].source, st) < 0) {
+       && ZIP_ENTRY_DATA_CHANGED(za->entries.entry+index)) {
+       if (zip_source_stat(za->entries.entry[index].source, st) < 0) {
            zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
            return -1;
        }
diff --git a/lib/zip_unchange.c b/lib/zip_unchange.c
index 5ef5462..b247994 100644
--- a/lib/zip_unchange.c
+++ b/lib/zip_unchange.c
@@ -50,13 +50,13 @@ _zip_unchange(zip_t *za, zip_uint64_t idx, int 
allow_duplicates)
     zip_int64_t i;
     const char *orig_name, *changed_name;
     
-    if (idx >= za->nentry) {
+    if (idx >= za->entries.nentry) {
        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
 
-    if (!allow_duplicates && za->entry[idx].changes && 
(za->entry[idx].changes->changed & ZIP_DIRENT_FILENAME)) {
-       if (za->entry[idx].orig != NULL) {
+    if (!allow_duplicates && za->entries.entry[idx].changes && 
(za->entries.entry[idx].changes->changed & ZIP_DIRENT_FILENAME)) {
+       if (za->entries.entry[idx].orig != NULL) {
            if ((orig_name=_zip_get_name(za, idx, ZIP_FL_UNCHANGED, 
&za->error)) == NULL) {
                return -1;
            }
@@ -86,10 +86,10 @@ _zip_unchange(zip_t *za, zip_uint64_t idx, int 
allow_duplicates)
        }
     }
 
-    _zip_dirent_free(za->entry[idx].changes);
-    za->entry[idx].changes = NULL;
+    _zip_dirent_free(za->entries.entry[idx].changes);
+    za->entries.entry[idx].changes = NULL;
 
-    _zip_unchange_data(za->entry+idx);
+    _zip_unchange_data(za->entries.entry+idx);
 
     return 0;
 }
diff --git a/lib/zip_unchange_all.c b/lib/zip_unchange_all.c
index dc89f7f..b5f380a 100644
--- a/lib/zip_unchange_all.c
+++ b/lib/zip_unchange_all.c
@@ -46,7 +46,7 @@ zip_unchange_all(zip_t *za)
     _zip_hash_revert(za->names);
     
     ret = 0;
-    for (i=0; i<za->nentry; i++)
+    for (i=0; i<za->entries.nentry; i++)
        ret |= _zip_unchange(za, i, 1);
 
     ret |= zip_unchange_archive(za);
diff --git a/lib/zipint.h b/lib/zipint.h
index 6939d73..5d8f425 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -167,6 +167,13 @@ typedef struct zip_extra_field zip_extra_field_t;
 typedef struct zip_string zip_string_t;
 typedef struct zip_buffer zip_buffer_t;
 typedef struct zip_hash zip_hash_t;
+typedef struct zip_array zip_array_t;
+
+struct zip_array {
+    zip_uint64_t nentry;               /* number of entries */
+    zip_uint64_t nentry_alloc;         /* number of entries allocated */
+    zip_entry_t *entry;                 /* entries */
+};
 
 /* zip archive, part of API */
 
@@ -184,9 +191,7 @@ struct zip {
     zip_string_t *comment_changes;     /* changed archive comment */
     bool comment_changed;              /* whether archive comment was changed 
*/
 
-    zip_uint64_t nentry;               /* number of entries */
-    zip_uint64_t nentry_alloc;         /* number of entries allocated */
-    zip_entry_t *entry;                 /* entries */
+    zip_array_t entries;                /* array of entries */
 
     unsigned int nopen_source;         /* number of open sources using archive 
*/
     unsigned int nopen_source_alloc;   /* number of sources allocated */
@@ -241,9 +246,7 @@ struct zip_dirent {
 /* zip archive central directory */
 
 struct zip_cdir {
-    zip_entry_t *entry;                        /* directory entries */
-    zip_uint64_t nentry;               /* number of entries */
-    zip_uint64_t nentry_alloc;         /* number of entries allocated */
+    zip_array_t entries;                /* array of entries */
 
     zip_uint64_t size;                  /* size of central directory */
     zip_uint64_t offset;               /* offset of central directory in file 
*/
-- 
2.6.3

Made by MHonArc.