_zip_buffer_data:
   39|  99.6k|zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer) {
   40|  99.6k|    return buffer->data;
   41|  99.6k|}
_zip_buffer_free:
   44|   199k|void _zip_buffer_free(zip_buffer_t *buffer) {
   45|   199k|    if (buffer == NULL) {
  ------------------
  |  Branch (45:9): [True: 165, False: 199k]
  ------------------
   46|    165|        return;
   47|    165|    }
   48|       |
   49|   199k|    if (buffer->free_data) {
  ------------------
  |  Branch (49:9): [True: 59.6k, False: 139k]
  ------------------
   50|  59.6k|        free(buffer->data);
   51|  59.6k|    }
   52|       |
   53|   199k|    free(buffer);
   54|   199k|}
_zip_buffer_eof:
   57|  55.0k|bool _zip_buffer_eof(zip_buffer_t *buffer) {
   58|  55.0k|    return buffer->ok && buffer->offset == buffer->size;
  ------------------
  |  Branch (58:12): [True: 54.9k, False: 117]
  |  Branch (58:26): [True: 44.4k, False: 10.4k]
  ------------------
   59|  55.0k|}
_zip_buffer_get:
   62|  41.2M|zip_uint8_t *_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length) {
   63|  41.2M|    zip_uint8_t *data;
   64|       |
   65|  41.2M|    data = _zip_buffer_peek(buffer, length);
   66|       |
   67|  41.2M|    if (data != NULL) {
  ------------------
  |  Branch (67:9): [True: 41.2M, False: 23.9k]
  ------------------
   68|  41.2M|        buffer->offset += length;
   69|  41.2M|    }
   70|       |
   71|  41.2M|    return data;
   72|  41.2M|}
_zip_buffer_get_16:
   75|  27.4M|zip_uint16_t _zip_buffer_get_16(zip_buffer_t *buffer) {
   76|  27.4M|    zip_uint8_t *data = _zip_buffer_get(buffer, 2);
   77|       |
   78|  27.4M|    if (data == NULL) {
  ------------------
  |  Branch (78:9): [True: 0, False: 27.4M]
  ------------------
   79|      0|        return 0;
   80|      0|    }
   81|       |
   82|  27.4M|    return (zip_uint16_t)(data[0] + (data[1] << 8));
   83|  27.4M|}
_zip_buffer_get_32:
   86|   428k|zip_uint32_t _zip_buffer_get_32(zip_buffer_t *buffer) {
   87|   428k|    zip_uint8_t *data = _zip_buffer_get(buffer, 4);
   88|       |
   89|   428k|    if (data == NULL) {
  ------------------
  |  Branch (89:9): [True: 22, False: 428k]
  ------------------
   90|     22|        return 0;
   91|     22|    }
   92|       |
   93|   428k|    return ((((((zip_uint32_t)data[3] << 8) + data[2]) << 8) + data[1]) << 8) + data[0];
   94|   428k|}
_zip_buffer_get_64:
   97|  13.4k|zip_uint64_t _zip_buffer_get_64(zip_buffer_t *buffer) {
   98|  13.4k|    zip_uint8_t *data = _zip_buffer_get(buffer, 8);
   99|       |
  100|  13.4k|    if (data == NULL) {
  ------------------
  |  Branch (100:9): [True: 111, False: 13.3k]
  ------------------
  101|    111|        return 0;
  102|    111|    }
  103|       |
  104|  13.3k|    return ((zip_uint64_t)data[7] << 56) + ((zip_uint64_t)data[6] << 48) + ((zip_uint64_t)data[5] << 40) + ((zip_uint64_t)data[4] << 32) + ((zip_uint64_t)data[3] << 24) + ((zip_uint64_t)data[2] << 16) + ((zip_uint64_t)data[1] << 8) + (zip_uint64_t)data[0];
  105|  13.4k|}
_zip_buffer_get_8:
  108|  2.81k|zip_uint8_t _zip_buffer_get_8(zip_buffer_t *buffer) {
  109|  2.81k|    zip_uint8_t *data = _zip_buffer_get(buffer, 1);
  110|       |
  111|  2.81k|    if (data == NULL) {
  ------------------
  |  Branch (111:9): [True: 0, False: 2.81k]
  ------------------
  112|      0|        return 0;
  113|      0|    }
  114|       |
  115|  2.81k|    return data[0];
  116|  2.81k|}
_zip_buffer_left:
  119|  13.3M|zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer) {
  120|  13.3M|    return buffer->ok ? buffer->size - buffer->offset : 0;
  ------------------
  |  Branch (120:12): [True: 13.3M, False: 0]
  ------------------
  121|  13.3M|}
_zip_buffer_new:
  142|   199k|zip_buffer_t *_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) {
  143|   199k|    bool free_data = (data == NULL);
  144|   199k|    zip_buffer_t *buffer;
  145|       |
  146|       |#if ZIP_UINT64_MAX > SIZE_MAX
  147|       |    if (size > SIZE_MAX) {
  148|       |        return NULL;
  149|       |    }
  150|       |#endif
  151|       |
  152|   199k|    if (data == NULL) {
  ------------------
  |  Branch (152:9): [True: 59.6k, False: 139k]
  ------------------
  153|  59.6k|        if ((data = (zip_uint8_t *)malloc((size_t)size)) == NULL) {
  ------------------
  |  Branch (153:13): [True: 0, False: 59.6k]
  ------------------
  154|      0|            return NULL;
  155|      0|        }
  156|  59.6k|    }
  157|       |
  158|   199k|    if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) {
  ------------------
  |  Branch (158:9): [True: 0, False: 199k]
  ------------------
  159|      0|        if (free_data) {
  ------------------
  |  Branch (159:13): [True: 0, False: 0]
  ------------------
  160|      0|            free(data);
  161|      0|        }
  162|      0|        return NULL;
  163|      0|    }
  164|       |
  165|   199k|    buffer->ok = true;
  166|   199k|    buffer->data = data;
  167|   199k|    buffer->size = size;
  168|   199k|    buffer->offset = 0;
  169|   199k|    buffer->free_data = free_data;
  170|       |
  171|   199k|    return buffer;
  172|   199k|}
_zip_buffer_new_from_source:
  175|   157k|zip_buffer_t *_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error) {
  176|   157k|    zip_buffer_t *buffer;
  177|       |
  178|   157k|    if ((buffer = _zip_buffer_new(buf, size)) == NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 157k]
  ------------------
  179|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  180|      0|        return NULL;
  181|      0|    }
  182|       |
  183|   157k|    if (_zip_read(src, buffer->data, size, error) < 0) {
  ------------------
  |  Branch (183:9): [True: 244, False: 157k]
  ------------------
  184|    244|        _zip_buffer_free(buffer);
  185|    244|        return NULL;
  186|    244|    }
  187|       |
  188|   157k|    return buffer;
  189|   157k|}
_zip_buffer_offset:
  192|  54.5k|zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer) {
  193|  54.5k|    return buffer->ok ? buffer->offset : 0;
  ------------------
  |  Branch (193:12): [True: 54.5k, False: 0]
  ------------------
  194|  54.5k|}
_zip_buffer_ok:
  197|  13.3M|bool _zip_buffer_ok(zip_buffer_t *buffer) {
  198|  13.3M|    return buffer->ok;
  199|  13.3M|}
_zip_buffer_peek:
  202|  41.2M|zip_uint8_t *_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length) {
  203|  41.2M|    zip_uint8_t *data;
  204|       |
  205|  41.2M|    if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) {
  ------------------
  |  Branch (205:9): [True: 16, False: 41.2M]
  |  Branch (205:24): [True: 0, False: 41.2M]
  |  Branch (205:60): [True: 23.9k, False: 41.2M]
  ------------------
  206|  23.9k|        buffer->ok = false;
  207|  23.9k|        return NULL;
  208|  23.9k|    }
  209|       |
  210|  41.2M|    data = buffer->data + buffer->offset;
  211|  41.2M|    return data;
  212|  41.2M|}
_zip_buffer_set_offset:
  289|  83.9k|int _zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset) {
  290|  83.9k|    if (offset > buffer->size) {
  ------------------
  |  Branch (290:9): [True: 12.6k, False: 71.3k]
  ------------------
  291|  12.6k|        buffer->ok = false;
  292|  12.6k|        return -1;
  293|  12.6k|    }
  294|       |
  295|  71.3k|    buffer->ok = true;
  296|  71.3k|    buffer->offset = offset;
  297|       |
  298|  71.3k|    return 0;
  299|  83.9k|}
_zip_buffer_skip:
  302|  25.7k|int _zip_buffer_skip(zip_buffer_t *buffer, zip_uint64_t length) {
  303|  25.7k|    zip_uint64_t offset = buffer->offset + length;
  304|       |
  305|  25.7k|    if (offset < buffer->offset) {
  ------------------
  |  Branch (305:9): [True: 0, False: 25.7k]
  ------------------
  306|      0|        buffer->ok = false;
  307|      0|        return -1;
  308|      0|    }
  309|  25.7k|    return _zip_buffer_set_offset(buffer, offset);
  310|  25.7k|}
_zip_buffer_size:
  312|  8.18k|zip_uint64_t _zip_buffer_size(zip_buffer_t *buffer) {
  313|  8.18k|    return buffer->size;
  314|  8.18k|}

zip_close:
   52|  1.20k|ZIP_EXTERN int zip_close(zip_t *za) {
   53|  1.20k|    zip_uint64_t i, j, survivors, unchanged_offset;
   54|  1.20k|    zip_int64_t off;
   55|  1.20k|    int error;
   56|  1.20k|    zip_filelist_t *filelist;
   57|  1.20k|    int changed;
   58|       |
   59|  1.20k|    if (za == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 1.20k]
  ------------------
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|  1.20k|    changed = _zip_changed(za, &survivors);
   64|       |
   65|  1.20k|    if (survivors == 0 && !(za->ch_flags & ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE)) {
  ------------------
  |  |  116|    483|#define ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE 16u /* don't remove file if archive is empty */
  ------------------
  |  Branch (65:9): [True: 483, False: 720]
  |  Branch (65:27): [True: 483, False: 0]
  ------------------
   66|       |        /* don't create zip files with no entries */
   67|    483|        if ((za->open_flags & ZIP_TRUNCATE) || changed) {
  ------------------
  |  |   89|    483|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (67:13): [True: 0, False: 483]
  |  Branch (67:48): [True: 0, False: 483]
  ------------------
   68|      0|            if (zip_source_remove(za->src) < 0) {
  ------------------
  |  Branch (68:17): [True: 0, False: 0]
  ------------------
   69|      0|                if (!((zip_error_code_zip(zip_source_error(za->src)) == ZIP_ER_REMOVE) && (zip_error_code_system(zip_source_error(za->src)) == ENOENT))) {
  ------------------
  |  |  153|      0|#define ZIP_ER_REMOVE 22          /* S Can't remove file */
  ------------------
  |  Branch (69:23): [True: 0, False: 0]
  |  Branch (69:91): [True: 0, False: 0]
  ------------------
   70|      0|                    zip_error_set_from_source(&za->error, za->src);
   71|      0|                    return -1;
   72|      0|                }
   73|      0|            }
   74|      0|        }
   75|    483|        zip_discard(za);
   76|    483|        return 0;
   77|    483|    }
   78|       |
   79|       |    /* Always write empty archive if we are told to keep it, otherwise it wouldn't be created if the file doesn't already exist. */
   80|    720|    if (!changed && survivors > 0) {
  ------------------
  |  Branch (80:9): [True: 720, False: 0]
  |  Branch (80:21): [True: 720, False: 0]
  ------------------
   81|    720|        zip_discard(za);
   82|    720|        return 0;
   83|    720|    }
   84|       |
   85|      0|    if (survivors > za->nentry) {
  ------------------
  |  Branch (85:9): [True: 0, False: 0]
  ------------------
   86|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   87|      0|        return -1;
   88|      0|    }
   89|       |
   90|      0|    if ((filelist = (zip_filelist_t *)malloc(sizeof(filelist[0]) * (size_t)survivors)) == NULL) {
  ------------------
  |  Branch (90:9): [True: 0, False: 0]
  ------------------
   91|      0|        return -1;
   92|      0|    }
   93|       |
   94|      0|    unchanged_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   95|       |    /* create list of files with index into original archive  */
   96|      0|    for (i = j = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (96:21): [True: 0, False: 0]
  ------------------
   97|      0|        if (za->entry[i].orig != NULL && ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
  ------------------
  |  |  519|      0|#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (518:35): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  517|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (517:34): [True: 0, False: 0]
  |  |  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (519:64): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (97:13): [True: 0, False: 0]
  ------------------
   98|      0|            unchanged_offset = ZIP_MIN(unchanged_offset, za->entry[i].orig->offset);
  ------------------
  |  |  515|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   99|      0|        }
  100|      0|        if (za->entry[i].deleted) {
  ------------------
  |  Branch (100:13): [True: 0, False: 0]
  ------------------
  101|      0|            continue;
  102|      0|        }
  103|       |
  104|      0|        if (j >= survivors) {
  ------------------
  |  Branch (104:13): [True: 0, False: 0]
  ------------------
  105|      0|            free(filelist);
  106|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  107|      0|            return -1;
  108|      0|        }
  109|       |
  110|      0|        filelist[j].idx = i;
  111|      0|        filelist[j].name = zip_get_name(za, i, 0);
  112|      0|        j++;
  113|      0|    }
  114|      0|    if (j < survivors) {
  ------------------
  |  Branch (114:9): [True: 0, False: 0]
  ------------------
  115|      0|        free(filelist);
  116|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  117|      0|        return -1;
  118|      0|    }
  119|       |
  120|      0|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|      0|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|      0|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  121|      0|        qsort(filelist, (size_t)survivors, sizeof(filelist[0]), torrentzip_compare_names);
  122|      0|    }
  123|       |
  124|      0|    if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
  ------------------
  |  |  523|      0|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|      0|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                  if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
  ------------------
  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (124:36): [True: 0, False: 0]
  ------------------
  125|      0|        unchanged_offset = 0;
  126|      0|    }
  127|      0|    else {
  128|      0|        if (unchanged_offset == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (128:13): [True: 0, False: 0]
  ------------------
  129|       |            /* we're keeping all file data, find the end of the last one */
  130|      0|            zip_uint64_t last_index = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  131|      0|            unchanged_offset = 0;
  132|       |
  133|      0|            for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (133:25): [True: 0, False: 0]
  ------------------
  134|      0|                if (za->entry[i].orig != NULL) {
  ------------------
  |  Branch (134:21): [True: 0, False: 0]
  ------------------
  135|      0|                    if (za->entry[i].orig->offset >= unchanged_offset) {
  ------------------
  |  Branch (135:25): [True: 0, False: 0]
  ------------------
  136|      0|                        unchanged_offset = za->entry[i].orig->offset;
  137|      0|                        last_index = i;
  138|      0|                    }
  139|      0|                }
  140|      0|            }
  141|      0|            if (last_index != ZIP_UINT64_MAX) {
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (141:17): [True: 0, False: 0]
  ------------------
  142|      0|                if ((unchanged_offset = _zip_file_get_end(za, last_index, &za->error)) == 0) {
  ------------------
  |  Branch (142:21): [True: 0, False: 0]
  ------------------
  143|      0|                    free(filelist);
  144|      0|                    return -1;
  145|      0|                }
  146|      0|            }
  147|      0|        }
  148|      0|        if (unchanged_offset > 0) {
  ------------------
  |  Branch (148:13): [True: 0, False: 0]
  ------------------
  149|      0|            if (zip_source_begin_write_cloning(za->src, unchanged_offset) < 0) {
  ------------------
  |  Branch (149:17): [True: 0, False: 0]
  ------------------
  150|       |                /* cloning not supported, need to copy everything */
  151|      0|                unchanged_offset = 0;
  152|      0|            }
  153|      0|        }
  154|      0|    }
  155|      0|    if (unchanged_offset == 0) {
  ------------------
  |  Branch (155:9): [True: 0, False: 0]
  ------------------
  156|      0|        if (zip_source_begin_write(za->src) < 0) {
  ------------------
  |  Branch (156:13): [True: 0, False: 0]
  ------------------
  157|      0|            zip_error_set_from_source(&za->error, za->src);
  158|      0|            free(filelist);
  159|      0|            return -1;
  160|      0|        }
  161|      0|    }
  162|       |
  163|      0|    if (_zip_progress_start(za->progress) != 0) {
  ------------------
  |  Branch (163:9): [True: 0, False: 0]
  ------------------
  164|      0|        zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
  ------------------
  |  |  163|      0|#define ZIP_ER_CANCELLED 32       /* N Operation cancelled */
  ------------------
  165|      0|        zip_source_rollback_write(za->src);
  166|      0|        free(filelist);
  167|      0|        return -1;
  168|      0|    }
  169|      0|    error = 0;
  170|      0|    for (j = 0; j < survivors; j++) {
  ------------------
  |  Branch (170:17): [True: 0, False: 0]
  ------------------
  171|      0|        int new_data;
  172|      0|        zip_entry_t *entry;
  173|      0|        zip_dirent_t *de;
  174|       |
  175|      0|        if (_zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors) != 0) {
  ------------------
  |  Branch (175:13): [True: 0, False: 0]
  ------------------
  176|      0|            zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
  ------------------
  |  |  163|      0|#define ZIP_ER_CANCELLED 32       /* N Operation cancelled */
  ------------------
  177|      0|            error = 1;
  178|      0|            break;
  179|      0|        }
  180|       |
  181|      0|        i = filelist[j].idx;
  182|      0|        entry = za->entry + i;
  183|       |
  184|      0|        if (entry->orig != NULL && entry->orig->offset < unchanged_offset) {
  ------------------
  |  Branch (184:13): [True: 0, False: 0]
  |  Branch (184:36): [True: 0, False: 0]
  ------------------
  185|       |            /* already implicitly copied by cloning */
  186|      0|            continue;
  187|      0|        }
  188|       |
  189|      0|        new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  ------------------
  |  |  |  Branch (518:35): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  517|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  ------------------
  |  |  |  Branch (517:34): [True: 0, False: 0]
  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  517|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  ------------------
  |  |  |  Branch (517:34): [True: 0, False: 0]
  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  523|      0|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|      0|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  522|      0|#define ZIP_IS_TORRENTZIP(za) ((za)->flags & ZIP_AFL_IS_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  114|      0|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  |  |  ------------------
  ------------------
  |  Branch (189:193): [True: 0, False: 0]
  ------------------
  190|       |
  191|       |        /* create new local directory entry */
  192|      0|        if (entry->changes == NULL) {
  ------------------
  |  Branch (192:13): [True: 0, False: 0]
  ------------------
  193|      0|            if ((entry->changes = _zip_dirent_clone(entry->orig)) == NULL) {
  ------------------
  |  Branch (193:17): [True: 0, False: 0]
  ------------------
  194|      0|                zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  195|      0|                error = 1;
  196|      0|                break;
  197|      0|            }
  198|      0|        }
  199|      0|        else if (entry->orig != NULL) {
  ------------------
  |  Branch (199:18): [True: 0, False: 0]
  ------------------
  200|      0|            if (!_zip_dirent_merge(entry->changes, entry->orig, ZIP_ENTRY_DATA_CHANGED(entry), &za->error)) {
  ------------------
  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  ------------------
  |  Branch (200:17): [True: 0, False: 0]
  ------------------
  201|      0|                error = 1;
  202|      0|                break;
  203|      0|            }
  204|      0|        }
  205|      0|        de = entry->changes;
  206|       |
  207|      0|        if (_zip_read_local_ef(za, i) < 0) {
  ------------------
  |  Branch (207:13): [True: 0, False: 0]
  ------------------
  208|      0|            error = 1;
  209|      0|            break;
  210|      0|        }
  211|       |
  212|      0|        if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|      0|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|      0|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  213|      0|            zip_dirent_torrentzip_normalize(entry->changes);
  214|      0|        }
  215|       |
  216|      0|        if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (216:13): [True: 0, False: 0]
  ------------------
  217|      0|            zip_error_set_from_source(&za->error, za->src);
  218|      0|            error = 1;
  219|      0|            break;
  220|      0|        }
  221|      0|        de->offset = (zip_uint64_t)off;
  222|       |
  223|      0|        if (new_data) {
  ------------------
  |  Branch (223:13): [True: 0, False: 0]
  ------------------
  224|      0|            zip_source_t *zs;
  225|       |
  226|      0|            zs = NULL;
  227|      0|            if (!ZIP_ENTRY_DATA_CHANGED(entry)) {
  ------------------
  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  ------------------
  |  Branch (227:17): [True: 0, False: 0]
  ------------------
  228|      0|                if ((zs = zip_source_zip_file_create(za, i, ZIP_FL_UNCHANGED, 0, -1, NULL, &za->error)) == NULL) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (228:21): [True: 0, False: 0]
  ------------------
  229|      0|                    error = 1;
  230|      0|                    break;
  231|      0|                }
  232|      0|            }
  233|       |
  234|       |            /* add_data writes dirent */
  235|      0|            if (add_data(za, zs ? zs : entry->source, de) < 0) {
  ------------------
  |  Branch (235:17): [True: 0, False: 0]
  |  Branch (235:30): [True: 0, False: 0]
  ------------------
  236|      0|                error = 1;
  237|      0|                if (zs) {
  ------------------
  |  Branch (237:21): [True: 0, False: 0]
  ------------------
  238|      0|                    zip_source_free(zs);
  239|      0|                }
  240|      0|                break;
  241|      0|            }
  242|      0|            if (zs) {
  ------------------
  |  Branch (242:17): [True: 0, False: 0]
  ------------------
  243|      0|                zip_source_free(zs);
  244|      0|            }
  245|      0|        }
  246|      0|        else {
  247|      0|            zip_uint64_t offset;
  248|       |
  249|      0|            if (de->encryption_method != ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|      0|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (249:17): [True: 0, False: 0]
  ------------------
  250|       |                /* when copying data, all sizes are known -> no data descriptor needed */
  251|       |                /* except for PKWare encryption, where removing the data descriptor breaks password validation */
  252|      0|                de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  254|      0|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  253|      0|            }
  254|      0|            if (_zip_dirent_write(za, de, ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (254:17): [True: 0, False: 0]
  ------------------
  255|      0|                error = 1;
  256|      0|                break;
  257|      0|            }
  258|      0|            if ((offset = _zip_file_get_offset(za, i, &za->error)) == 0) {
  ------------------
  |  Branch (258:17): [True: 0, False: 0]
  ------------------
  259|      0|                error = 1;
  260|      0|                break;
  261|      0|            }
  262|      0|            if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (262:17): [True: 0, False: 0]
  ------------------
  263|      0|                zip_error_set_from_source(&za->error, za->src);
  264|      0|                error = 1;
  265|      0|                break;
  266|      0|            }
  267|      0|            if (copy_data(za, de->comp_size) < 0) {
  ------------------
  |  Branch (267:17): [True: 0, False: 0]
  ------------------
  268|      0|                error = 1;
  269|      0|                break;
  270|      0|            }
  271|       |
  272|      0|            if (de->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
  ------------------
  |  |  254|      0|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  |  Branch (272:17): [True: 0, False: 0]
  ------------------
  273|      0|                if (write_data_descriptor(za, de, _zip_dirent_needs_zip64(de, 0)) < 0) {
  ------------------
  |  Branch (273:21): [True: 0, False: 0]
  ------------------
  274|      0|                    error = 1;
  275|      0|                    break;
  276|      0|                }
  277|      0|            }
  278|      0|        }
  279|      0|    }
  280|       |
  281|      0|    if (!error) {
  ------------------
  |  Branch (281:9): [True: 0, False: 0]
  ------------------
  282|      0|        if (write_cdir(za, filelist, survivors) < 0) {
  ------------------
  |  Branch (282:13): [True: 0, False: 0]
  ------------------
  283|      0|            error = 1;
  284|      0|        }
  285|      0|    }
  286|       |
  287|      0|    free(filelist);
  288|       |
  289|      0|    if (!error) {
  ------------------
  |  Branch (289:9): [True: 0, False: 0]
  ------------------
  290|      0|        if (zip_source_commit_write(za->src) != 0) {
  ------------------
  |  Branch (290:13): [True: 0, False: 0]
  ------------------
  291|      0|            zip_error_set_from_source(&za->error, za->src);
  292|      0|            error = 1;
  293|      0|        }
  294|      0|        _zip_progress_end(za->progress);
  295|      0|    }
  296|       |
  297|      0|    if (error) {
  ------------------
  |  Branch (297:9): [True: 0, False: 0]
  ------------------
  298|      0|        zip_source_rollback_write(za->src);
  299|      0|        return -1;
  300|      0|    }
  301|       |
  302|      0|    zip_discard(za);
  303|       |
  304|      0|    return 0;
  305|      0|}
_zip_changed:
  731|  1.20k|int _zip_changed(const zip_t *za, zip_uint64_t *survivorsp) {
  732|  1.20k|    int changed;
  733|  1.20k|    zip_uint64_t i, survivors;
  734|       |
  735|  1.20k|    changed = 0;
  736|  1.20k|    survivors = 0;
  737|       |
  738|  1.20k|    if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
  ------------------
  |  |  523|  2.40k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  1.20k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 1.20k]
  |  |  ------------------
  ------------------
                  if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
  ------------------
  |  |  522|      0|#define ZIP_IS_TORRENTZIP(za) ((za)->flags & ZIP_AFL_IS_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  114|      0|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  |  |  ------------------
  ------------------
  |  Branch (738:9): [True: 0, False: 1.20k]
  |  Branch (738:60): [True: 0, False: 0]
  ------------------
  739|      0|        changed = 1;
  740|      0|    }
  741|       |
  742|  24.9k|    for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (742:17): [True: 23.7k, False: 1.20k]
  ------------------
  743|  23.7k|        if (ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
  ------------------
  |  |  519|  23.7k|#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  518|  47.4k|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (518:35): [True: 0, False: 23.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  517|  23.7k|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (517:34): [True: 0, False: 23.7k]
  |  |  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (519:64): [True: 0, False: 23.7k]
  |  |  ------------------
  ------------------
  744|      0|            changed = 1;
  745|      0|        }
  746|  23.7k|        if (!za->entry[i].deleted) {
  ------------------
  |  Branch (746:13): [True: 23.7k, False: 0]
  ------------------
  747|  23.7k|            survivors++;
  748|  23.7k|        }
  749|  23.7k|    }
  750|       |
  751|  1.20k|    if (survivorsp) {
  ------------------
  |  Branch (751:9): [True: 1.20k, False: 0]
  ------------------
  752|  1.20k|        *survivorsp = survivors;
  753|  1.20k|    }
  754|       |
  755|  1.20k|    return changed;
  756|  1.20k|}

_zip_cdir_free:
   49|  24.5k|void _zip_cdir_free(zip_cdir_t *cd) {
   50|  24.5k|    zip_uint64_t i;
   51|       |
   52|  24.5k|    if (cd == NULL) {
  ------------------
  |  Branch (52:9): [True: 0, False: 24.5k]
  ------------------
   53|      0|        return;
   54|      0|    }
   55|       |
   56|  30.3M|    for (i = 0; i < cd->nentry; i++) {
  ------------------
  |  Branch (56:17): [True: 30.3M, False: 24.5k]
  ------------------
   57|  30.3M|        _zip_entry_finalize(cd->entry + i);
   58|  30.3M|    }
   59|  24.5k|    free(cd->entry);
   60|  24.5k|    _zip_string_free(cd->comment);
   61|  24.5k|    free(cd);
   62|  24.5k|}
_zip_cdir_new:
   65|  25.7k|zip_cdir_t *_zip_cdir_new(zip_error_t *error) {
   66|  25.7k|    zip_cdir_t *cd;
   67|       |
   68|  25.7k|    if ((cd = (zip_cdir_t *)malloc(sizeof(*cd))) == NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 25.7k]
  ------------------
   69|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   70|      0|        return NULL;
   71|      0|    }
   72|       |
   73|  25.7k|    cd->entry = NULL;
   74|  25.7k|    cd->nentry = cd->nentry_alloc = 0;
   75|  25.7k|    cd->size = cd->offset = 0;
   76|  25.7k|    cd->comment = NULL;
   77|  25.7k|    cd->is_zip64 = false;
   78|       |
   79|  25.7k|    return cd;
   80|  25.7k|}
_zip_cdir_grow:
   83|  2.68k|bool _zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error) {
   84|  2.68k|    zip_uint64_t i;
   85|       |
   86|  2.68k|    if (additional_entries == 0) {
  ------------------
  |  Branch (86:9): [True: 809, False: 1.87k]
  ------------------
   87|    809|        return true;
   88|    809|    }
   89|       |
   90|  1.87k|    if (!ZIP_REALLOC(cd->entry, cd->nentry_alloc, additional_entries, error)) {
  ------------------
  |  |  107|  1.87k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (90:9): [True: 0, False: 1.87k]
  ------------------
   91|      0|        return false;
   92|      0|    }
   93|       |
   94|  30.3M|    for (i = cd->nentry; i < cd->nentry_alloc; i++) {
  ------------------
  |  Branch (94:26): [True: 30.3M, False: 1.87k]
  ------------------
   95|  30.3M|        _zip_entry_init(cd->entry + i);
   96|  30.3M|    }
   97|       |
   98|  1.87k|    cd->nentry = cd->nentry_alloc;
   99|       |
  100|       |    return true;
  101|  1.87k|}
_zip_dirent_finalize:
  233|  73.3k|void _zip_dirent_finalize(zip_dirent_t *zde) {
  234|  73.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  337|      0|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (234:9): [True: 73.3k, False: 0]
  |  Branch (234:25): [True: 0, False: 0]
  ------------------
  235|  73.3k|        _zip_string_free(zde->filename);
  236|  73.3k|        zde->filename = NULL;
  237|  73.3k|    }
  238|  73.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_EXTRA_FIELD) {
  ------------------
  |  |  339|      0|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  |  Branch (238:9): [True: 73.3k, False: 0]
  |  Branch (238:25): [True: 0, False: 0]
  ------------------
  239|  73.3k|        _zip_extra_fields_fini(&zde->extra_fields);
  240|  73.3k|    }
  241|  73.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_COMMENT) {
  ------------------
  |  |  338|      0|#define ZIP_DIRENT_COMMENT 0x0004u
  ------------------
  |  Branch (241:9): [True: 73.3k, False: 0]
  |  Branch (241:25): [True: 0, False: 0]
  ------------------
  242|  73.3k|        _zip_string_free(zde->comment);
  243|  73.3k|        zde->comment = NULL;
  244|  73.3k|    }
  245|  73.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_PASSWORD) {
  ------------------
  |  |  343|      0|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (245:9): [True: 73.3k, False: 0]
  |  Branch (245:25): [True: 0, False: 0]
  ------------------
  246|  73.3k|        if (zde->password) {
  ------------------
  |  Branch (246:13): [True: 0, False: 73.3k]
  ------------------
  247|      0|            _zip_crypto_clear(zde->password, strlen(zde->password));
  ------------------
  |  |  533|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  248|      0|        }
  249|  73.3k|        free(zde->password);
  250|       |        zde->password = NULL;
  251|  73.3k|    }
  252|  73.3k|}
_zip_dirent_free:
  255|  60.6M|void _zip_dirent_free(zip_dirent_t *zde) {
  256|  60.6M|    if (zde == NULL) {
  ------------------
  |  Branch (256:9): [True: 60.6M, False: 73.3k]
  ------------------
  257|  60.6M|        return;
  258|  60.6M|    }
  259|       |
  260|  73.3k|    _zip_dirent_finalize(zde);
  261|  73.3k|    free(zde);
  262|  73.3k|}
_zip_dirent_init:
  313|   146k|void _zip_dirent_init(zip_dirent_t *de) {
  314|   146k|    de->changed = 0;
  315|   146k|    de->local_extra_fields_read = 0;
  316|   146k|    de->cloned = 0;
  317|       |
  318|   146k|    de->crc_valid = true;
  319|   146k|    de->last_mod_mtime_valid = false;
  320|   146k|    de->version_madeby = 63 | (ZIP_OPSYS_DEFAULT << 8);
  ------------------
  |  |  246|   146k|#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
  |  |  ------------------
  |  |  |  |  228|   146k|#define ZIP_OPSYS_UNIX 0x03u
  |  |  ------------------
  ------------------
  321|   146k|    de->version_needed = 10; /* 1.0 */
  322|   146k|    de->bitflags = 0;
  323|   146k|    de->comp_method = ZIP_CM_DEFAULT;
  ------------------
  |  |  178|   146k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  324|   146k|    de->last_mod.date = 0;
  325|   146k|    de->last_mod.time = 0;
  326|   146k|    de->crc = 0;
  327|   146k|    de->comp_size = 0;
  328|   146k|    de->uncomp_size = 0;
  329|   146k|    de->filename = NULL;
  330|   146k|    _zip_extra_fields_init(&de->extra_fields);
  331|   146k|    de->comment = NULL;
  332|   146k|    de->disk_number = 0;
  333|   146k|    de->int_attrib = 0;
  334|   146k|    de->ext_attrib = ZIP_EXT_ATTRIB_DEFAULT;
  ------------------
  |  |   97|   146k|#define ZIP_EXT_ATTRIB_DEFAULT (0100666u << 16)
  ------------------
  335|   146k|    de->offset = 0;
  336|   146k|    de->compression_level = 0;
  337|   146k|    de->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|   146k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  338|       |    de->password = NULL;
  339|   146k|}
_zip_dirent_new:
  351|  73.3k|zip_dirent_t *_zip_dirent_new(void) {
  352|  73.3k|    zip_dirent_t *de;
  353|       |
  354|  73.3k|    if ((de = (zip_dirent_t *)malloc(sizeof(*de))) == NULL) {
  ------------------
  |  Branch (354:9): [True: 0, False: 73.3k]
  ------------------
  355|      0|        return NULL;
  356|      0|    }
  357|       |
  358|  73.3k|    _zip_dirent_init(de);
  359|  73.3k|    return de;
  360|  73.3k|}
_zip_dirent_read:
  373|  73.3k|zip_int64_t _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, bool is_zip64, zip_uint64_t central_compressed_size, bool check_consistency, zip_error_t *error) {
  374|  73.3k|    zip_uint8_t buf[CDENTRYSIZE];
  375|  73.3k|    zip_uint32_t size, variable_size;
  376|  73.3k|    zip_uint16_t filename_len, comment_len, ef_len;
  377|  73.3k|    zip_string_t *utf8_string;
  378|  73.3k|    zip_extra_field_t **efp;
  379|       |
  380|  73.3k|    bool from_buffer = (buffer != NULL);
  381|       |
  382|  73.3k|    size = local ? LENTRYSIZE : CDENTRYSIZE;
  ------------------
  |  |   59|      0|#define LENTRYSIZE 30
  ------------------
                  size = local ? LENTRYSIZE : CDENTRYSIZE;
  ------------------
  |  |   58|   146k|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (382:12): [True: 0, False: 73.3k]
  ------------------
  383|       |
  384|  73.3k|    if (buffer) {
  ------------------
  |  Branch (384:9): [True: 17.3k, False: 56.0k]
  ------------------
  385|  17.3k|        if (_zip_buffer_left(buffer) < size) {
  ------------------
  |  Branch (385:13): [True: 126, False: 17.2k]
  ------------------
  386|    126|            zip_error_set(error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|    126|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  387|    126|            return -1;
  388|    126|        }
  389|  17.3k|    }
  390|  56.0k|    else {
  391|  56.0k|        if ((buffer = _zip_buffer_new_from_source(src, size, buf, error)) == NULL) {
  ------------------
  |  Branch (391:13): [True: 12, False: 55.9k]
  ------------------
  392|     12|            return -1;
  393|     12|        }
  394|  56.0k|    }
  395|       |
  396|  73.1k|    if (memcmp(_zip_buffer_get(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
  ------------------
  |  |   52|      0|#define LOCAL_MAGIC "PK\3\4"
  ------------------
                  if (memcmp(_zip_buffer_get(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
  ------------------
  |  |   51|  73.1k|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (396:9): [True: 93, False: 73.0k]
  |  Branch (396:45): [True: 0, False: 73.1k]
  ------------------
  397|     93|        zip_error_set(error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|     93|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  398|     93|        if (!from_buffer) {
  ------------------
  |  Branch (398:13): [True: 39, False: 54]
  ------------------
  399|     39|            _zip_buffer_free(buffer);
  400|     39|        }
  401|     93|        return -1;
  402|     93|    }
  403|       |
  404|       |    /* convert buffercontents to zip_dirent */
  405|       |
  406|  73.0k|    _zip_dirent_init(zde);
  407|  73.0k|    if (!local) {
  ------------------
  |  Branch (407:9): [True: 73.0k, False: 0]
  ------------------
  408|  73.0k|        zde->version_madeby = _zip_buffer_get_16(buffer);
  409|  73.0k|    }
  410|      0|    else {
  411|      0|        zde->version_madeby = 0;
  412|      0|    }
  413|  73.0k|    zde->version_needed = _zip_buffer_get_16(buffer);
  414|  73.0k|    zde->bitflags = _zip_buffer_get_16(buffer);
  415|  73.0k|    zde->comp_method = _zip_buffer_get_16(buffer);
  416|       |
  417|       |    /* convert to time_t */
  418|  73.0k|    zde->last_mod.time = _zip_buffer_get_16(buffer);
  419|  73.0k|    zde->last_mod.date = _zip_buffer_get_16(buffer);
  420|       |
  421|  73.0k|    zde->crc = _zip_buffer_get_32(buffer);
  422|  73.0k|    zde->comp_size = _zip_buffer_get_32(buffer);
  423|  73.0k|    zde->uncomp_size = _zip_buffer_get_32(buffer);
  424|       |
  425|  73.0k|    filename_len = _zip_buffer_get_16(buffer);
  426|  73.0k|    ef_len = _zip_buffer_get_16(buffer);
  427|       |
  428|  73.0k|    if (local) {
  ------------------
  |  Branch (428:9): [True: 0, False: 73.0k]
  ------------------
  429|      0|        comment_len = 0;
  430|      0|        zde->disk_number = 0;
  431|      0|        zde->int_attrib = 0;
  432|      0|        zde->ext_attrib = 0;
  433|      0|        zde->offset = 0;
  434|      0|    }
  435|  73.0k|    else {
  436|  73.0k|        comment_len = _zip_buffer_get_16(buffer);
  437|  73.0k|        zde->disk_number = _zip_buffer_get_16(buffer);
  438|  73.0k|        zde->int_attrib = _zip_buffer_get_16(buffer);
  439|  73.0k|        zde->ext_attrib = _zip_buffer_get_32(buffer);
  440|  73.0k|        zde->offset = _zip_buffer_get_32(buffer);
  441|  73.0k|    }
  442|       |
  443|  73.0k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (443:9): [True: 0, False: 73.0k]
  ------------------
  444|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  445|      0|        if (!from_buffer) {
  ------------------
  |  Branch (445:13): [True: 0, False: 0]
  ------------------
  446|      0|            _zip_buffer_free(buffer);
  447|      0|        }
  448|      0|        return -1;
  449|      0|    }
  450|       |
  451|  73.0k|    if (zde->bitflags & ZIP_GPBF_ENCRYPTED) {
  ------------------
  |  |  253|  73.0k|#define ZIP_GPBF_ENCRYPTED 0x0001u         /* is encrypted */
  ------------------
  |  Branch (451:9): [True: 6.49k, False: 66.6k]
  ------------------
  452|  6.49k|        if (zde->bitflags & ZIP_GPBF_STRONG_ENCRYPTION) {
  ------------------
  |  |  255|  6.49k|#define ZIP_GPBF_STRONG_ENCRYPTION 0x0040u /* uses strong encryption */
  ------------------
  |  Branch (452:13): [True: 3.63k, False: 2.86k]
  ------------------
  453|       |            /* TODO */
  454|  3.63k|            zde->encryption_method = ZIP_EM_UNKNOWN;
  ------------------
  |  |  223|  3.63k|#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
  ------------------
  455|  3.63k|        }
  456|  2.86k|        else {
  457|  2.86k|            zde->encryption_method = ZIP_EM_TRAD_PKWARE;
  ------------------
  |  |  208|  2.86k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  458|  2.86k|        }
  459|  6.49k|    }
  460|  66.6k|    else {
  461|  66.6k|        zde->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  66.6k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  462|  66.6k|    }
  463|       |
  464|  73.0k|    zde->filename = NULL;
  465|  73.0k|    _zip_extra_fields_init(&zde->extra_fields);
  466|  73.0k|    zde->comment = NULL;
  467|       |
  468|  73.0k|    variable_size = (zip_uint32_t)filename_len + (zip_uint32_t)ef_len + (zip_uint32_t)comment_len;
  469|       |
  470|  73.0k|    if (from_buffer) {
  ------------------
  |  Branch (470:9): [True: 17.1k, False: 55.9k]
  ------------------
  471|  17.1k|        if (_zip_buffer_left(buffer) < variable_size) {
  ------------------
  |  Branch (471:13): [True: 60, False: 17.0k]
  ------------------
  472|     60|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  152|     60|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  233|     60|#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW 12           /* E variable size fields overflow header */
  ------------------
  473|     60|            return -1;
  474|     60|        }
  475|  17.1k|    }
  476|  55.9k|    else {
  477|  55.9k|        _zip_buffer_free(buffer);
  478|       |
  479|  55.9k|        if ((buffer = _zip_buffer_new_from_source(src, variable_size, NULL, error)) == NULL) {
  ------------------
  |  Branch (479:13): [True: 22, False: 55.9k]
  ------------------
  480|     22|            return -1;
  481|     22|        }
  482|  55.9k|    }
  483|       |
  484|  73.0k|    if (filename_len) {
  ------------------
  |  Branch (484:9): [True: 63.7k, False: 9.22k]
  ------------------
  485|  63.7k|        zde->filename = _zip_read_string(buffer, src, filename_len, 1, error);
  486|  63.7k|        if (zde->filename == NULL) {
  ------------------
  |  Branch (486:13): [True: 0, False: 63.7k]
  ------------------
  487|      0|            if (zip_error_code_zip(error) == ZIP_ER_EOF) {
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  |  Branch (487:17): [True: 0, False: 0]
  ------------------
  488|      0|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  233|      0|#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW 12           /* E variable size fields overflow header */
  ------------------
  489|      0|            }
  490|      0|            if (!from_buffer) {
  ------------------
  |  Branch (490:17): [True: 0, False: 0]
  ------------------
  491|      0|                _zip_buffer_free(buffer);
  492|      0|            }
  493|      0|            return -1;
  494|      0|        }
  495|       |
  496|  63.7k|        if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
  ------------------
  |  |  256|  63.7k|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  |  Branch (496:13): [True: 1.75k, False: 62.0k]
  ------------------
  497|  1.75k|            if (_zip_guess_encoding(zde->filename, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (497:17): [True: 15, False: 1.74k]
  ------------------
  498|     15|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME);
  ------------------
  |  |  152|     15|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME);
  ------------------
  |  |  234|     15|#define ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME 13         /* E invalid UTF-8 in filename */
  ------------------
  499|     15|                if (!from_buffer) {
  ------------------
  |  Branch (499:21): [True: 7, False: 8]
  ------------------
  500|      7|                    _zip_buffer_free(buffer);
  501|      7|                }
  502|     15|                return -1;
  503|     15|            }
  504|  1.75k|        }
  505|       |
  506|  63.7k|        if (check_consistency) {
  ------------------
  |  Branch (506:13): [True: 0, False: 63.7k]
  ------------------
  507|      0|            zip_uint8_t *p;
  508|       |
  509|      0|            for (p = zde->filename->raw; p < zde->filename->raw + zde->filename->length; p++) {
  ------------------
  |  Branch (509:42): [True: 0, False: 0]
  ------------------
  510|      0|                if (*p == 0) {
  ------------------
  |  Branch (510:21): [True: 0, False: 0]
  ------------------
  511|      0|                    zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_NUL_IN_FILENAME);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                                  zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_NUL_IN_FILENAME);
  ------------------
  |  |  247|      0|#define ZIP_ER_DETAIL_NUL_IN_FILENAME 26                  /* E NUL byte in file name */
  ------------------
  512|      0|                    if (!from_buffer) {
  ------------------
  |  Branch (512:25): [True: 0, False: 0]
  ------------------
  513|      0|                        _zip_buffer_free(buffer);
  514|      0|                    }
  515|      0|                    return -1;
  516|      0|                }
  517|      0|            }
  518|      0|        }
  519|  63.7k|    }
  520|       |
  521|  73.0k|    if (ef_len) {
  ------------------
  |  Branch (521:9): [True: 5.89k, False: 67.1k]
  ------------------
  522|  5.89k|        zip_uint8_t *ef = _zip_read_data(buffer, src, ef_len, 0, error);
  523|       |
  524|  5.89k|        if (ef == NULL) {
  ------------------
  |  Branch (524:13): [True: 0, False: 5.89k]
  ------------------
  525|      0|            if (!from_buffer) {
  ------------------
  |  Branch (525:17): [True: 0, False: 0]
  ------------------
  526|      0|                _zip_buffer_free(buffer);
  527|      0|            }
  528|      0|            return -1;
  529|      0|        }
  530|  5.89k|        if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, (local ? &zde->extra_fields.local : &zde->extra_fields.central), error)) {
  ------------------
  |  |  260|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
                      if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, (local ? &zde->extra_fields.local : &zde->extra_fields.central), error)) {
  ------------------
  |  |  261|  5.89k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  5.89k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (530:13): [True: 96, False: 5.79k]
  |  Branch (530:40): [True: 0, False: 5.89k]
  |  Branch (530:80): [True: 0, False: 5.89k]
  ------------------
  531|     96|            free(ef);
  532|     96|            if (!from_buffer) {
  ------------------
  |  Branch (532:17): [True: 16, False: 80]
  ------------------
  533|     16|                _zip_buffer_free(buffer);
  534|     16|            }
  535|     96|            return -1;
  536|     96|        }
  537|  5.79k|        free(ef);
  538|  5.79k|        if (local) {
  ------------------
  |  Branch (538:13): [True: 0, False: 5.79k]
  ------------------
  539|      0|            zde->local_extra_fields_read = 1;
  540|      0|        }
  541|  5.79k|    }
  542|       |
  543|  72.9k|    if (comment_len) {
  ------------------
  |  Branch (543:9): [True: 6.56k, False: 66.3k]
  ------------------
  544|  6.56k|        zde->comment = _zip_read_string(buffer, src, comment_len, 0, error);
  545|  6.56k|        if (zde->comment == NULL) {
  ------------------
  |  Branch (545:13): [True: 0, False: 6.56k]
  ------------------
  546|      0|            if (!from_buffer) {
  ------------------
  |  Branch (546:17): [True: 0, False: 0]
  ------------------
  547|      0|                _zip_buffer_free(buffer);
  548|      0|            }
  549|      0|            return -1;
  550|      0|        }
  551|  6.56k|        if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
  ------------------
  |  |  256|  6.56k|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  |  Branch (551:13): [True: 1.97k, False: 4.59k]
  ------------------
  552|  1.97k|            if (_zip_guess_encoding(zde->comment, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (552:17): [True: 4, False: 1.97k]
  ------------------
  553|      4|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT);
  ------------------
  |  |  152|      4|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT);
  ------------------
  |  |  235|      4|#define ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT 14          /* E invalid UTF-8 in comment */
  ------------------
  554|      4|                if (!from_buffer) {
  ------------------
  |  Branch (554:21): [True: 1, False: 3]
  ------------------
  555|      1|                    _zip_buffer_free(buffer);
  556|      1|                }
  557|      4|                return -1;
  558|      4|            }
  559|  1.97k|        }
  560|  6.56k|    }
  561|       |
  562|  72.9k|    if ((utf8_string = _zip_dirent_process_ef_utf_8(zde, ZIP_EF_UTF_8_NAME, zde->filename, check_consistency)) == NULL && zde->filename != NULL) {
  ------------------
  |  |   90|  72.9k|#define ZIP_EF_UTF_8_NAME 0x7075
  ------------------
  |  Branch (562:9): [True: 8.80k, False: 64.0k]
  |  Branch (562:123): [True: 0, False: 8.80k]
  ------------------
  563|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH);
  ------------------
  |  |  244|      0|#define ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH 23           /* E UTF-8 filename is ASCII and doesn't match filename */
  ------------------
  564|      0|        if (!from_buffer) {
  ------------------
  |  Branch (564:13): [True: 0, False: 0]
  ------------------
  565|      0|            _zip_buffer_free(buffer);
  566|      0|        }
  567|      0|        return -1;
  568|      0|    }
  569|  72.9k|    zde->filename = utf8_string;
  570|  72.9k|    if (!local) {
  ------------------
  |  Branch (570:9): [True: 72.9k, False: 0]
  ------------------
  571|  72.9k|        if ((utf8_string = _zip_dirent_process_ef_utf_8(zde, ZIP_EF_UTF_8_COMMENT, zde->comment, check_consistency)) == NULL && zde->comment != NULL) {
  ------------------
  |  |   89|  72.9k|#define ZIP_EF_UTF_8_COMMENT 0x6375
  ------------------
  |  Branch (571:13): [True: 66.3k, False: 6.59k]
  |  Branch (571:129): [True: 0, False: 66.3k]
  ------------------
  572|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH);
  ------------------
  |  |  245|      0|#define ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH 24            /* E UTF-8 comment is ASCII and doesn't match comment */
  ------------------
  573|      0|            if (!from_buffer) {
  ------------------
  |  Branch (573:17): [True: 0, False: 0]
  ------------------
  574|      0|                _zip_buffer_free(buffer);
  575|      0|            }
  576|      0|            return -1;
  577|      0|        }
  578|  72.9k|        zde->comment = utf8_string;
  579|  72.9k|    }
  580|       |
  581|       |    /* Zip64 */
  582|       |
  583|  72.9k|    if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|   145k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|   140k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  67.3k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (583:9): [True: 4.90k, False: 68.0k]
  |  Branch (583:47): [True: 611, False: 67.3k]
  |  Branch (583:83): [True: 1.20k, False: 66.1k]
  ------------------
  584|  6.72k|        zip_uint16_t got_len;
  585|  6.72k|        const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
  ------------------
  |  |   92|  6.72k|#define ZIP_EF_ZIP64 0x0001
  ------------------
                      const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
  ------------------
  |  |  260|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
                      const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
  ------------------
  |  |  261|  6.72k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  6.72k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (585:108): [True: 0, False: 6.72k]
  ------------------
  586|  6.72k|        if (ef != NULL) {
  ------------------
  |  Branch (586:13): [True: 1.60k, False: 5.11k]
  ------------------
  587|  1.60k|            if (!zip_dirent_process_ef_zip64(zde, ef, got_len, local, error)) {
  ------------------
  |  Branch (587:17): [True: 368, False: 1.23k]
  ------------------
  588|    368|                if (!from_buffer) {
  ------------------
  |  Branch (588:21): [True: 2, False: 366]
  ------------------
  589|      2|                    _zip_buffer_free(buffer);
  590|      2|                }
  591|    368|                return -1;
  592|    368|            }
  593|  1.60k|        }
  594|  5.11k|        else if (is_zip64) {
  ------------------
  |  Branch (594:18): [True: 0, False: 5.11k]
  ------------------
  595|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_MISSING_ZIP64_EF);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_MISSING_ZIP64_EF);
  ------------------
  |  |  248|      0|#define ZIP_ER_DETAIL_MISSING_ZIP64_EF 27                 /* E missing Zip64 extra field */
  ------------------
  596|      0|            if (!from_buffer) {
  ------------------
  |  Branch (596:17): [True: 0, False: 0]
  ------------------
  597|      0|                _zip_buffer_free(buffer);
  598|      0|            }
  599|      0|            return -1;
  600|      0|        }
  601|  6.72k|    }
  602|       |
  603|       |
  604|  72.5k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (604:9): [True: 0, False: 72.5k]
  ------------------
  605|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  606|      0|        if (!from_buffer) {
  ------------------
  |  Branch (606:13): [True: 0, False: 0]
  ------------------
  607|      0|            _zip_buffer_free(buffer);
  608|      0|        }
  609|      0|        return -1;
  610|      0|    }
  611|       |
  612|  72.5k|    if (!from_buffer) {
  ------------------
  |  Branch (612:9): [True: 55.9k, False: 16.6k]
  ------------------
  613|  55.9k|        _zip_buffer_free(buffer);
  614|  55.9k|    }
  615|       |
  616|  72.5k|    if (local && zde->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
  ------------------
  |  |  254|      0|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  |  Branch (616:9): [True: 0, False: 72.5k]
  |  Branch (616:18): [True: 0, False: 0]
  ------------------
  617|      0|        zip_uint32_t df_crc;
  618|      0|        zip_uint64_t df_comp_size, df_uncomp_size;
  619|       |
  620|      0|        if (zip_source_seek(src, central_compressed_size, SEEK_CUR) != 0 || (buffer = _zip_buffer_new_from_source(src, MAX_DATA_DESCRIPTOR_LENGTH, buf, error)) == NULL) {
  ------------------
  |  |   69|      0|#define MAX_DATA_DESCRIPTOR_LENGTH 24
  ------------------
  |  Branch (620:13): [True: 0, False: 0]
  |  Branch (620:77): [True: 0, False: 0]
  ------------------
  621|      0|            return -1;
  622|      0|        }
  623|      0|        if (memcmp(_zip_buffer_peek(buffer, MAGIC_LEN), DATADES_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   57|      0|#define MAGIC_LEN 4
  ------------------
                      if (memcmp(_zip_buffer_peek(buffer, MAGIC_LEN), DATADES_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   54|      0|#define DATADES_MAGIC "PK\7\10"
  ------------------
                      if (memcmp(_zip_buffer_peek(buffer, MAGIC_LEN), DATADES_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   57|      0|#define MAGIC_LEN 4
  ------------------
  |  Branch (623:13): [True: 0, False: 0]
  ------------------
  624|      0|            _zip_buffer_skip(buffer, MAGIC_LEN);
  ------------------
  |  |   57|      0|#define MAGIC_LEN 4
  ------------------
  625|      0|        }
  626|      0|        df_crc = _zip_buffer_get_32(buffer);
  627|      0|        df_comp_size = is_zip64 ? _zip_buffer_get_64(buffer) : _zip_buffer_get_32(buffer);
  ------------------
  |  Branch (627:24): [True: 0, False: 0]
  ------------------
  628|      0|        df_uncomp_size = is_zip64 ? _zip_buffer_get_64(buffer) : _zip_buffer_get_32(buffer);
  ------------------
  |  Branch (628:26): [True: 0, False: 0]
  ------------------
  629|       |
  630|      0|        if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (630:13): [True: 0, False: 0]
  ------------------
  631|      0|            zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  632|      0|            _zip_buffer_free(buffer);
  633|      0|            return -1;
  634|      0|        }
  635|      0|        _zip_buffer_free(buffer);
  636|       |
  637|       |        /* According to the appnote, it should be 0, but some implementations write the actual value. */
  638|      0|        if ((zde->crc != 0 && zde->crc != df_crc) || (zde->comp_size != 0 && zde->comp_size != df_comp_size) || (zde->uncomp_size != 0 && zde->uncomp_size != df_uncomp_size)) {
  ------------------
  |  Branch (638:14): [True: 0, False: 0]
  |  Branch (638:31): [True: 0, False: 0]
  |  Branch (638:55): [True: 0, False: 0]
  |  Branch (638:78): [True: 0, False: 0]
  |  Branch (638:114): [True: 0, False: 0]
  |  Branch (638:139): [True: 0, False: 0]
  ------------------
  639|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_DATA_DESCRIPTOR_MISMATCH);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_DATA_DESCRIPTOR_MISMATCH);
  ------------------
  |  |  242|      0|#define ZIP_ER_DETAIL_DATA_DESCRIPTOR_MISMATCH 21         /* E local header and data descriptor do not match */
  ------------------
  640|      0|            return -1;
  641|      0|        }
  642|      0|        zde->crc = df_crc;
  643|      0|        zde->comp_size = df_comp_size;
  644|      0|        zde->uncomp_size = df_uncomp_size;
  645|      0|    }
  646|       |
  647|       |    /* zip_source_seek / zip_source_tell don't support values > ZIP_INT64_MAX */
  648|  72.5k|    if (zde->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  72.5k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (648:9): [True: 66, False: 72.4k]
  ------------------
  649|     66|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|     66|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  650|     66|        return -1;
  651|     66|    }
  652|       |
  653|  72.4k|    if (!_zip_dirent_process_winzip_aes(zde, error)) {
  ------------------
  |  Branch (653:9): [True: 55, False: 72.4k]
  ------------------
  654|     55|        return -1;
  655|     55|    }
  656|       |
  657|  72.4k|    efp = local ? &zde->extra_fields.local : &zde->extra_fields.central;
  ------------------
  |  Branch (657:11): [True: 0, False: 72.4k]
  ------------------
  658|  72.4k|    *efp = _zip_ef_remove_internal(*efp);
  659|       |
  660|  72.4k|    return (zip_int64_t)size + (zip_int64_t)variable_size;
  661|  72.4k|}
zip_dirent_process_ef_zip64:
  663|  1.60k|bool zip_dirent_process_ef_zip64(zip_dirent_t *zde, const zip_uint8_t *ef, zip_uint64_t got_len, bool local, zip_error_t *error) {
  664|  1.60k|    zip_buffer_t *ef_buffer;
  665|       |
  666|  1.60k|    if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
  ------------------
  |  Branch (666:9): [True: 0, False: 1.60k]
  ------------------
  667|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  668|      0|        return false;
  669|      0|    }
  670|       |
  671|  1.60k|    if (zde->uncomp_size == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  1.60k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (671:9): [True: 1.24k, False: 364]
  ------------------
  672|  1.24k|        zde->uncomp_size = _zip_buffer_get_64(ef_buffer);
  673|  1.24k|    }
  674|    364|    else if (local) {
  ------------------
  |  Branch (674:14): [True: 0, False: 364]
  ------------------
  675|       |        /* From appnote.txt: This entry in the Local header MUST
  676|       |           include BOTH original and compressed file size fields. */
  677|      0|        (void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
  678|      0|    }
  679|  1.60k|    if (zde->comp_size == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  1.60k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (679:9): [True: 1.19k, False: 409]
  ------------------
  680|  1.19k|        zde->comp_size = _zip_buffer_get_64(ef_buffer);
  681|  1.19k|    }
  682|  1.60k|    if (!local) {
  ------------------
  |  Branch (682:9): [True: 1.60k, False: 0]
  ------------------
  683|  1.60k|        if (zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  1.60k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (683:13): [True: 970, False: 635]
  ------------------
  684|    970|            zde->offset = _zip_buffer_get_64(ef_buffer);
  685|    970|        }
  686|  1.60k|        if (zde->disk_number == ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  1.60k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (686:13): [True: 45, False: 1.56k]
  ------------------
  687|     45|            zde->disk_number = _zip_buffer_get_32(ef_buffer);
  688|     45|        }
  689|  1.60k|    }
  690|       |
  691|  1.60k|    if (!_zip_buffer_eof(ef_buffer)) {
  ------------------
  |  Branch (691:9): [True: 1.29k, False: 314]
  ------------------
  692|       |        /* accept additional fields if values match */
  693|  1.29k|        bool ok = true;
  694|  1.29k|        switch (got_len) {
  695|  1.16k|        case 28:
  ------------------
  |  Branch (695:9): [True: 1.16k, False: 122]
  ------------------
  696|  1.16k|            _zip_buffer_set_offset(ef_buffer, 24);
  697|  1.16k|            if (zde->disk_number != _zip_buffer_get_32(ef_buffer)) {
  ------------------
  |  Branch (697:17): [True: 213, False: 956]
  ------------------
  698|    213|                ok = false;
  699|    213|            }
  700|       |            /* fallthrough */
  701|  1.17k|        case 24:
  ------------------
  |  Branch (701:9): [True: 10, False: 1.28k]
  ------------------
  702|  1.17k|            _zip_buffer_set_offset(ef_buffer, 0);
  703|  1.17k|            if ((zde->uncomp_size != _zip_buffer_get_64(ef_buffer)) || (zde->comp_size != _zip_buffer_get_64(ef_buffer)) || (zde->offset != _zip_buffer_get_64(ef_buffer))) {
  ------------------
  |  Branch (703:17): [True: 87, False: 1.09k]
  |  Branch (703:72): [True: 83, False: 1.00k]
  |  Branch (703:125): [True: 86, False: 923]
  ------------------
  704|    256|                ok = false;
  705|    256|            }
  706|  1.17k|            break;
  707|       |
  708|    112|        default:
  ------------------
  |  Branch (708:9): [True: 112, False: 1.17k]
  ------------------
  709|    112|            ok = false;
  710|  1.29k|        }
  711|  1.29k|        if (!ok) {
  ------------------
  |  Branch (711:13): [True: 368, False: 923]
  ------------------
  712|    368|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_ZIP64_EF);
  ------------------
  |  |  152|    368|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_ZIP64_EF);
  ------------------
  |  |  236|    368|#define ZIP_ER_DETAIL_INVALID_ZIP64_EF 15                 /* E invalid Zip64 extra field */
  ------------------
  713|    368|            _zip_buffer_free(ef_buffer);
  714|    368|            return false;
  715|    368|        }
  716|  1.29k|    }
  717|  1.23k|    _zip_buffer_free(ef_buffer);
  718|       |
  719|       |    return true;
  720|  1.60k|}
_zip_d2u_time:
 1164|  23.7k|time_t _zip_d2u_time(const zip_dostime_t *dtime) {
 1165|  23.7k|    struct tm tm;
 1166|       |
 1167|  23.7k|    memset(&tm, 0, sizeof(tm));
 1168|       |
 1169|       |    /* let mktime decide if DST is in effect */
 1170|  23.7k|    tm.tm_isdst = -1;
 1171|       |
 1172|  23.7k|    tm.tm_year = ((dtime->date >> 9) & 127) + 1980 - 1900;
 1173|  23.7k|    tm.tm_mon = ((dtime->date >> 5) & 15) - 1;
 1174|  23.7k|    tm.tm_mday = dtime->date & 31;
 1175|       |
 1176|  23.7k|    tm.tm_hour = (dtime->time >> 11) & 31;
 1177|  23.7k|    tm.tm_min = (dtime->time >> 5) & 63;
 1178|  23.7k|    tm.tm_sec = (dtime->time << 1) & 62;
 1179|       |
 1180|  23.7k|    return mktime(&tm);
 1181|  23.7k|}
_zip_get_dirent:
 1222|   516k|zip_dirent_t *_zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
 1223|   516k|    if (error == NULL) {
  ------------------
  |  Branch (1223:9): [True: 71.2k, False: 445k]
  ------------------
 1224|  71.2k|        error = &za->error;
 1225|  71.2k|    }
 1226|       |
 1227|   516k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (1227:9): [True: 0, False: 516k]
  ------------------
 1228|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1229|      0|        return NULL;
 1230|      0|    }
 1231|       |
 1232|   516k|    if ((flags & ZIP_FL_UNCHANGED) || za->entry[idx].changes == NULL) {
  ------------------
  |  |   98|   516k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (1232:9): [True: 0, False: 516k]
  |  Branch (1232:39): [True: 516k, False: 0]
  ------------------
 1233|   516k|        if (za->entry[idx].orig == NULL) {
  ------------------
  |  Branch (1233:13): [True: 0, False: 516k]
  ------------------
 1234|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1235|      0|            return NULL;
 1236|      0|        }
 1237|   516k|        if (za->entry[idx].deleted && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (1237:13): [True: 0, False: 516k]
  |  Branch (1237:39): [True: 0, False: 0]
  ------------------
 1238|      0|            zip_error_set(error, ZIP_ER_DELETED, 0);
  ------------------
  |  |  154|      0|#define ZIP_ER_DELETED 23         /* N Entry has been deleted */
  ------------------
 1239|      0|            return NULL;
 1240|      0|        }
 1241|   516k|        return za->entry[idx].orig;
 1242|   516k|    }
 1243|      0|    else {
 1244|      0|        return za->entry[idx].changes;
 1245|      0|    }
 1246|   516k|}
zip_dirent_get_last_mod_mtime:
 1391|  23.7k|time_t zip_dirent_get_last_mod_mtime(zip_dirent_t *de) {
 1392|  23.7k|    if (!de->last_mod_mtime_valid) {
  ------------------
  |  Branch (1392:9): [True: 23.7k, False: 0]
  ------------------
 1393|  23.7k|        de->last_mod_mtime = _zip_d2u_time(&de->last_mod);
 1394|  23.7k|        de->last_mod_mtime_valid = true;
 1395|  23.7k|    }
 1396|       |
 1397|  23.7k|    return de->last_mod_mtime;
 1398|  23.7k|}
zip_dirent.c:_zip_dirent_process_ef_utf_8:
  723|   145k|static zip_string_t *_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str, bool check_consistency) {
  724|   145k|    zip_uint16_t ef_len;
  725|   145k|    zip_uint32_t ef_crc;
  726|   145k|    zip_buffer_t *buffer;
  727|       |
  728|   145k|    const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&de->extra_fields, &ef_len, id, 0, ZIP_EF_BOTH, NULL);
  ------------------
  |  |  262|   145k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|   145k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|   145k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|   145k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|   145k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  729|       |
  730|   145k|    if (ef == NULL || ef_len < 5 || ef[0] != 1) {
  ------------------
  |  Branch (730:9): [True: 142k, False: 3.00k]
  |  Branch (730:23): [True: 101, False: 2.90k]
  |  Branch (730:37): [True: 104, False: 2.79k]
  ------------------
  731|   143k|        return str;
  732|   143k|    }
  733|       |
  734|  2.79k|    if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) {
  ------------------
  |  Branch (734:9): [True: 0, False: 2.79k]
  ------------------
  735|      0|        return str;
  736|      0|    }
  737|       |
  738|  2.79k|    _zip_buffer_get_8(buffer);
  739|  2.79k|    ef_crc = _zip_buffer_get_32(buffer);
  740|       |
  741|  2.79k|    if (_zip_string_crc32(str) == ef_crc) {
  ------------------
  |  Branch (741:9): [True: 2.48k, False: 316]
  ------------------
  742|  2.48k|        zip_uint16_t len = (zip_uint16_t)_zip_buffer_left(buffer);
  743|  2.48k|        zip_string_t *ef_str = _zip_string_new(_zip_buffer_get(buffer, len), len, ZIP_FL_ENC_UTF_8, NULL);
  ------------------
  |  |  107|  2.48k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
  744|       |
  745|  2.48k|        if (ef_str != NULL) {
  ------------------
  |  Branch (745:13): [True: 377, False: 2.10k]
  ------------------
  746|    377|            if (check_consistency) {
  ------------------
  |  Branch (746:17): [True: 0, False: 377]
  ------------------
  747|      0|                if (!_zip_string_equal(str, ef_str) && _zip_string_is_ascii(ef_str)) {
  ------------------
  |  Branch (747:21): [True: 0, False: 0]
  |  Branch (747:56): [True: 0, False: 0]
  ------------------
  748|      0|                    _zip_string_free(ef_str);
  749|      0|                    _zip_buffer_free(buffer);
  750|      0|                    return NULL;
  751|      0|                }
  752|      0|            }
  753|       |
  754|    377|            _zip_string_free(str);
  755|    377|            str = ef_str;
  756|    377|        }
  757|  2.48k|    }
  758|       |
  759|  2.79k|    _zip_buffer_free(buffer);
  760|       |
  761|  2.79k|    return str;
  762|  2.79k|}
zip_dirent.c:_zip_dirent_process_winzip_aes:
  765|  72.4k|static bool _zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error) {
  766|  72.4k|    zip_uint16_t ef_len;
  767|  72.4k|    zip_buffer_t *buffer;
  768|  72.4k|    const zip_uint8_t *ef;
  769|  72.4k|    bool crc_valid;
  770|  72.4k|    zip_uint16_t enc_method;
  771|       |
  772|       |
  773|  72.4k|    if (de->comp_method != ZIP_CM_WINZIP_AES) {
  ------------------
  |  |   79|  72.4k|#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
  ------------------
  |  Branch (773:9): [True: 72.4k, False: 58]
  ------------------
  774|  72.4k|        return true;
  775|  72.4k|    }
  776|       |
  777|     58|    ef = _zip_extra_fields_get_by_id(&de->extra_fields, &ef_len, ZIP_EF_WINZIP_AES, 0, ZIP_EF_BOTH, NULL);
  ------------------
  |  |   91|     58|#define ZIP_EF_WINZIP_AES 0x9901
  ------------------
                  ef = _zip_extra_fields_get_by_id(&de->extra_fields, &ef_len, ZIP_EF_WINZIP_AES, 0, ZIP_EF_BOTH, NULL);
  ------------------
  |  |  262|     58|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|     58|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|     58|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|     58|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|     58|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|       |
  779|     58|    if (ef == NULL || ef_len < 7) {
  ------------------
  |  Branch (779:9): [True: 4, False: 54]
  |  Branch (779:23): [True: 3, False: 51]
  ------------------
  780|      7|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  152|      7|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  237|      7|#define ZIP_ER_DETAIL_INVALID_WINZIPAES_EF 16             /* E invalid WinZip AES extra field */
  ------------------
  781|      7|        return false;
  782|      7|    }
  783|       |
  784|     51|    if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) {
  ------------------
  |  Branch (784:9): [True: 0, False: 51]
  ------------------
  785|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  786|      0|        return false;
  787|      0|    }
  788|       |
  789|       |    /* version */
  790|       |
  791|     51|    crc_valid = true;
  792|     51|    switch (_zip_buffer_get_16(buffer)) {
  793|     37|    case 1:
  ------------------
  |  Branch (793:5): [True: 37, False: 14]
  ------------------
  794|     37|        break;
  795|       |
  796|     13|    case 2:
  ------------------
  |  Branch (796:5): [True: 13, False: 38]
  ------------------
  797|     13|        crc_valid = false;
  798|       |        /* TODO: When checking consistency, check that crc is 0. */
  799|     13|        break;
  800|       |
  801|      1|    default:
  ------------------
  |  Branch (801:5): [True: 1, False: 50]
  ------------------
  802|      1|        zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      1|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  803|      1|        _zip_buffer_free(buffer);
  804|      1|        return false;
  805|     51|    }
  806|       |
  807|       |    /* vendor */
  808|     50|    if (memcmp(_zip_buffer_get(buffer, 2), "AE", 2) != 0) {
  ------------------
  |  Branch (808:9): [True: 35, False: 15]
  ------------------
  809|     35|        zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|     35|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  810|     35|        _zip_buffer_free(buffer);
  811|     35|        return false;
  812|     35|    }
  813|       |
  814|       |    /* mode */
  815|     15|    switch (_zip_buffer_get_8(buffer)) {
  816|      3|    case 1:
  ------------------
  |  Branch (816:5): [True: 3, False: 12]
  ------------------
  817|      3|        enc_method = ZIP_EM_AES_128;
  ------------------
  |  |  220|      3|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
  818|      3|        break;
  819|      4|    case 2:
  ------------------
  |  Branch (819:5): [True: 4, False: 11]
  ------------------
  820|      4|        enc_method = ZIP_EM_AES_192;
  ------------------
  |  |  221|      4|#define ZIP_EM_AES_192 0x0102
  ------------------
  821|      4|        break;
  822|      2|    case 3:
  ------------------
  |  Branch (822:5): [True: 2, False: 13]
  ------------------
  823|      2|        enc_method = ZIP_EM_AES_256;
  ------------------
  |  |  222|      2|#define ZIP_EM_AES_256 0x0103
  ------------------
  824|      2|        break;
  825|      6|    default:
  ------------------
  |  Branch (825:5): [True: 6, False: 9]
  ------------------
  826|      6|        zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      6|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  827|      6|        _zip_buffer_free(buffer);
  828|      6|        return false;
  829|     15|    }
  830|       |
  831|      9|    if (ef_len != 7) {
  ------------------
  |  Branch (831:9): [True: 6, False: 3]
  ------------------
  832|      6|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  152|      6|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  237|      6|#define ZIP_ER_DETAIL_INVALID_WINZIPAES_EF 16             /* E invalid WinZip AES extra field */
  ------------------
  833|      6|        _zip_buffer_free(buffer);
  834|      6|        return false;
  835|      6|    }
  836|       |
  837|      3|    de->crc_valid = crc_valid;
  838|      3|    de->encryption_method = enc_method;
  839|      3|    de->comp_method = _zip_buffer_get_16(buffer);
  840|       |
  841|      3|    _zip_buffer_free(buffer);
  842|       |    return true;
  843|      9|}

zip_discard:
   45|  3.72k|void zip_discard(zip_t *za) {
   46|  3.72k|    zip_uint64_t i;
   47|       |
   48|  3.72k|    if (za == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 3.72k]
  ------------------
   49|      0|        return;
   50|      0|    }
   51|       |
   52|  3.72k|    if (za->src) {
  ------------------
  |  Branch (52:9): [True: 3.72k, False: 0]
  ------------------
   53|  3.72k|        zip_source_close(za->src);
   54|  3.72k|        zip_source_free(za->src);
   55|  3.72k|    }
   56|       |
   57|  3.72k|    if (za->default_password != NULL) {
  ------------------
  |  Branch (57:9): [True: 0, False: 3.72k]
  ------------------
   58|      0|        _zip_crypto_clear(za->default_password, strlen(za->default_password));
  ------------------
  |  |  533|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
   59|      0|    }
   60|  3.72k|    free(za->default_password);
   61|  3.72k|    _zip_string_free(za->comment_orig);
   62|  3.72k|    _zip_string_free(za->comment_changes);
   63|       |
   64|  3.72k|    _zip_hash_free(za->names);
   65|       |
   66|  3.72k|    if (za->entry) {
  ------------------
  |  Branch (66:9): [True: 720, False: 3.00k]
  ------------------
   67|  24.4k|        for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (67:21): [True: 23.7k, False: 720]
  ------------------
   68|  23.7k|            _zip_entry_finalize(za->entry + i);
   69|  23.7k|        }
   70|    720|        free(za->entry);
   71|    720|    }
   72|       |
   73|  3.72k|    for (i = 0; i < za->nopen_source; i++) {
  ------------------
  |  Branch (73:17): [True: 0, False: 3.72k]
  ------------------
   74|      0|        _zip_source_invalidate(za->open_source[i]);
   75|      0|    }
   76|  3.72k|    free(za->open_source);
   77|       |
   78|  3.72k|    _zip_progress_free(za->progress);
   79|       |
   80|  3.72k|    zip_error_fini(&za->error);
   81|       |
   82|  3.72k|    free(za);
   83|       |
   84|  3.72k|    return;
   85|  3.72k|}

_zip_entry_finalize:
   37|  30.3M|void _zip_entry_finalize(zip_entry_t *e) {
   38|  30.3M|    _zip_unchange_data(e);
   39|  30.3M|    _zip_dirent_free(e->orig);
   40|  30.3M|    _zip_dirent_free(e->changes);
   41|  30.3M|}
_zip_entry_init:
   44|  30.3M|void _zip_entry_init(zip_entry_t *e) {
   45|  30.3M|    e->orig = NULL;
   46|  30.3M|    e->changes = NULL;
   47|       |    e->source = NULL;
   48|  30.3M|    e->deleted = 0;
   49|  30.3M|}

zip_error_code_system:
   39|  92.4k|ZIP_EXTERN int zip_error_code_system(const zip_error_t *error) {
   40|  92.4k|    return error->sys_err;
   41|  92.4k|}
zip_error_code_zip:
   44|  95.4k|ZIP_EXTERN int zip_error_code_zip(const zip_error_t *error) {
   45|  95.4k|    return error->zip_err;
   46|  95.4k|}
zip_error_fini:
   49|  7.44k|ZIP_EXTERN void zip_error_fini(zip_error_t *err) {
   50|  7.44k|    free(err->str);
   51|       |    err->str = NULL;
   52|  7.44k|}
zip_error_init:
   55|  15.2k|ZIP_EXTERN void zip_error_init(zip_error_t *err) {
   56|  15.2k|    err->zip_err = ZIP_ER_OK;
  ------------------
  |  |  131|  15.2k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   57|  15.2k|    err->sys_err = 0;
   58|       |    err->str = NULL;
   59|  15.2k|}
_zip_error_clear:
   86|  3.97k|void _zip_error_clear(zip_error_t *err) {
   87|  3.97k|    if (err == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 3.97k]
  ------------------
   88|      0|        return;
   89|      0|    }
   90|       |
   91|  3.97k|    err->zip_err = ZIP_ER_OK;
  ------------------
  |  |  131|  3.97k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   92|  3.97k|    err->sys_err = 0;
   93|  3.97k|}
_zip_error_copy:
   96|  96.7k|void _zip_error_copy(zip_error_t *dst, const zip_error_t *src) {
   97|  96.7k|    if (dst == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 96.7k]
  ------------------
   98|      0|        return;
   99|      0|    }
  100|       |
  101|  96.7k|    dst->zip_err = src->zip_err;
  102|  96.7k|    dst->sys_err = src->sys_err;
  103|  96.7k|}
zip_error_set:
  121|   563k|void zip_error_set(zip_error_t *err, int ze, int se) {
  122|   563k|    if (err) {
  ------------------
  |  Branch (122:9): [True: 418k, False: 144k]
  ------------------
  123|   418k|        err->zip_err = ze;
  124|   418k|        err->sys_err = se;
  125|   418k|    }
  126|   563k|}
zip_error_set_from_source:
  129|  91.7k|void zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {
  130|  91.7k|    if (src == NULL) {
  ------------------
  |  Branch (130:9): [True: 0, False: 91.7k]
  ------------------
  131|      0|        zip_error_set(err, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  132|      0|        return;
  133|      0|    }
  134|       |
  135|  91.7k|    _zip_error_copy(err, zip_source_error(src));
  136|  91.7k|}
zip_error_to_data:
  139|  91.9k|zip_int64_t zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) {
  140|  91.9k|    int *e = (int *)data;
  141|       |
  142|  91.9k|    if (length < sizeof(int) * 2) {
  ------------------
  |  Branch (142:9): [True: 0, False: 91.9k]
  ------------------
  143|      0|        return -1;
  144|      0|    }
  145|       |
  146|  91.9k|    e[0] = zip_error_code_zip(error);
  147|  91.9k|    e[1] = zip_error_code_system(error);
  148|  91.9k|    return sizeof(int) * 2;
  149|  91.9k|}

_zip_ef_free:
  103|   187k|void _zip_ef_free(zip_extra_field_t *ef) {
  104|   187k|    zip_extra_field_t *ef2;
  105|       |
  106|  13.3M|    while (ef) {
  ------------------
  |  Branch (106:12): [True: 13.1M, False: 187k]
  ------------------
  107|  13.1M|        ef2 = ef->next;
  108|  13.1M|        free(ef->data);
  109|  13.1M|        free(ef);
  110|  13.1M|        ef = ef2;
  111|  13.1M|    }
  112|   187k|}
_zip_ef_find:
  114|   473k|zip_extra_field_t *_zip_ef_find(zip_extra_field_t *ef_head, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_extra_field_t **prev) {
  115|   473k|    zip_extra_field_t *ef;
  116|   473k|    zip_uint16_t i;
  117|       |
  118|   473k|    i = 0;
  119|  18.4M|    for (ef = ef_head; ef; ef = ef->next) {
  ------------------
  |  Branch (119:24): [True: 18.0M, False: 468k]
  ------------------
  120|  18.0M|        if (ef->id == ef_id) {
  ------------------
  |  Branch (120:13): [True: 5.24k, False: 18.0M]
  ------------------
  121|  5.24k|            if (i == ef_idx) {
  ------------------
  |  Branch (121:17): [True: 5.24k, False: 0]
  ------------------
  122|  5.24k|                return ef;
  123|  5.24k|            }
  124|      0|            i++;
  125|      0|        }
  126|  18.0M|        if (prev) {
  ------------------
  |  Branch (126:13): [True: 0, False: 18.0M]
  ------------------
  127|      0|            *prev = ef;
  128|      0|        }
  129|  18.0M|    }
  130|       |
  131|   468k|    return NULL;
  132|   473k|}
_zip_ef_get_by_id:
  135|   473k|const zip_uint8_t *_zip_ef_get_by_id(const zip_extra_field_t *ef_head, zip_uint16_t *lenp, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags) {
  136|   473k|    static const zip_uint8_t empty[1] = {'\0'};
  137|       |
  138|   473k|    zip_extra_field_t *ef = _zip_ef_find((zip_extra_field_t *)ef_head, id, id_idx, NULL);
  139|       |
  140|   473k|    if (ef) {
  ------------------
  |  Branch (140:9): [True: 5.24k, False: 468k]
  ------------------
  141|  5.24k|        if (lenp) {
  ------------------
  |  Branch (141:13): [True: 5.24k, False: 0]
  ------------------
  142|  5.24k|            *lenp = ef->size;
  143|  5.24k|        }
  144|  5.24k|        if (ef->size > 0) {
  ------------------
  |  Branch (144:13): [True: 4.71k, False: 536]
  ------------------
  145|  4.71k|            return ef->data;
  146|  4.71k|        }
  147|    536|        else {
  148|    536|            return empty;
  149|    536|        }
  150|  5.24k|    }
  151|       |
  152|   468k|    return NULL;
  153|   473k|}
_zip_ef_new:
  155|  13.1M|zip_extra_field_t *_zip_ef_new(zip_uint16_t id, zip_uint16_t size, const zip_uint8_t *data) {
  156|  13.1M|    zip_extra_field_t *ef;
  157|       |
  158|  13.1M|    if ((ef = (zip_extra_field_t *)malloc(sizeof(*ef))) == NULL) {
  ------------------
  |  Branch (158:9): [True: 0, False: 13.1M]
  ------------------
  159|      0|        return NULL;
  160|      0|    }
  161|       |
  162|  13.1M|    ef->next = NULL;
  163|  13.1M|    ef->id = id;
  164|  13.1M|    ef->size = size;
  165|  13.1M|    if (size > 0) {
  ------------------
  |  Branch (165:9): [True: 180k, False: 13.0M]
  ------------------
  166|   180k|        if ((ef->data = (zip_uint8_t *)_zip_memdup(data, size, NULL)) == NULL) {
  ------------------
  |  Branch (166:13): [True: 0, False: 180k]
  ------------------
  167|      0|            free(ef);
  168|      0|            return NULL;
  169|      0|        }
  170|   180k|    }
  171|  13.0M|    else {
  172|  13.0M|        ef->data = NULL;
  173|  13.0M|    }
  174|       |
  175|  13.1M|    return ef;
  176|  13.1M|}
_zip_ef_parse:
  179|  35.3k|bool _zip_ef_parse(const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags, zip_extra_field_t **ef_head_p, zip_error_t *error) {
  180|  35.3k|    zip_buffer_t *buffer;
  181|  35.3k|    zip_extra_field_t *ef, *ef2, *ef_head;
  182|       |
  183|  35.3k|    if ((buffer = _zip_buffer_new((zip_uint8_t *)data, len)) == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 35.3k]
  ------------------
  184|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  185|      0|        return false;
  186|      0|    }
  187|       |
  188|  35.3k|    ef_head = ef = NULL;
  189|       |
  190|  13.2M|    while (_zip_buffer_ok(buffer) && _zip_buffer_left(buffer) >= 4) {
  ------------------
  |  Branch (190:12): [True: 13.2M, False: 0]
  |  Branch (190:38): [True: 13.2M, False: 11.8k]
  ------------------
  191|  13.2M|        zip_uint16_t fid, flen;
  192|  13.2M|        zip_uint8_t *ef_data;
  193|       |
  194|  13.2M|        fid = _zip_buffer_get_16(buffer);
  195|  13.2M|        flen = _zip_buffer_get_16(buffer);
  196|  13.2M|        ef_data = _zip_buffer_get(buffer, flen);
  197|       |
  198|  13.2M|        if (ef_data == NULL) {
  ------------------
  |  Branch (198:13): [True: 23.4k, False: 13.1M]
  ------------------
  199|  23.4k|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_EF_LENGTH);
  ------------------
  |  |  152|  23.4k|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_EF_LENGTH);
  ------------------
  |  |  239|  23.4k|#define ZIP_ER_DETAIL_INVALID_EF_LENGTH 18                /* E extra field length is invalid */
  ------------------
  200|  23.4k|            _zip_buffer_free(buffer);
  201|  23.4k|            _zip_ef_free(ef_head);
  202|  23.4k|            return false;
  203|  23.4k|        }
  204|       |
  205|  13.1M|        if ((ef2 = _zip_ef_new(fid, flen, ef_data)) == NULL) {
  ------------------
  |  Branch (205:13): [True: 0, False: 13.1M]
  ------------------
  206|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  207|      0|            _zip_buffer_free(buffer);
  208|      0|            _zip_ef_free(ef_head);
  209|      0|            return false;
  210|      0|        }
  211|       |
  212|  13.1M|        if (ef_head) {
  ------------------
  |  Branch (212:13): [True: 13.1M, False: 25.0k]
  ------------------
  213|  13.1M|            ef->next = ef2;
  214|  13.1M|            ef = ef2;
  215|  13.1M|        }
  216|  25.0k|        else {
  217|  25.0k|            ef_head = ef = ef2;
  218|  25.0k|        }
  219|  13.1M|    }
  220|       |
  221|  11.8k|    if (!_zip_buffer_eof(buffer)) {
  ------------------
  |  Branch (221:9): [True: 9.31k, False: 2.54k]
  ------------------
  222|       |        /* Android APK files align stored file data with padding in extra fields; ignore. */
  223|       |        /* see https://android.googlesource.com/platform/build/+/master/tools/zipalign/ZipAlign.cpp */
  224|       |        /* buffer is at most 64k long, so this can't overflow. */
  225|  9.31k|        size_t glen = _zip_buffer_left(buffer);
  226|  9.31k|        zip_uint8_t *garbage;
  227|  9.31k|        garbage = _zip_buffer_get(buffer, glen);
  228|  9.31k|        if (glen >= 4 || garbage == NULL || memcmp(garbage, "\0\0\0", (size_t)glen) != 0) {
  ------------------
  |  Branch (228:13): [True: 0, False: 9.31k]
  |  Branch (228:26): [True: 0, False: 9.31k]
  |  Branch (228:45): [True: 3.69k, False: 5.62k]
  ------------------
  229|  3.69k|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EF_TRAILING_GARBAGE);
  ------------------
  |  |  152|  3.69k|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EF_TRAILING_GARBAGE);
  ------------------
  |  |  238|  3.69k|#define ZIP_ER_DETAIL_EF_TRAILING_GARBAGE 17              /* E garbage at end of extra fields */
  ------------------
  230|  3.69k|            _zip_buffer_free(buffer);
  231|  3.69k|            _zip_ef_free(ef_head);
  232|  3.69k|            return false;
  233|  3.69k|        }
  234|  9.31k|    }
  235|       |
  236|  8.16k|    _zip_buffer_free(buffer);
  237|       |
  238|  8.16k|    if (ef_head_p) {
  ------------------
  |  Branch (238:9): [True: 8.16k, False: 0]
  ------------------
  239|  8.16k|        *ef_head_p = ef_head;
  240|  8.16k|    }
  241|      0|    else {
  242|      0|        _zip_ef_free(ef_head);
  243|      0|    }
  244|       |
  245|       |    return true;
  246|  11.8k|}
_zip_ef_remove_internal:
  249|  74.3k|zip_extra_field_t *_zip_ef_remove_internal(zip_extra_field_t *ef) {
  250|  74.3k|    zip_extra_field_t *ef_head;
  251|  74.3k|    zip_extra_field_t *prev, *next;
  252|       |
  253|  74.3k|    ef_head = ef;
  254|  74.3k|    prev = NULL;
  255|       |
  256|  3.23M|    while (ef) {
  ------------------
  |  Branch (256:12): [True: 3.16M, False: 74.3k]
  ------------------
  257|  3.16M|        if (ZIP_EF_IS_INTERNAL(ef->id)) {
  ------------------
  |  |   94|  3.16M|#define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
  |  |  ------------------
  |  |  |  |   89|  6.32M|#define ZIP_EF_UTF_8_COMMENT 0x6375
  |  |  ------------------
  |  |               #define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
  |  |  ------------------
  |  |  |  |   90|  6.32M|#define ZIP_EF_UTF_8_NAME 0x7075
  |  |  ------------------
  |  |               #define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
  |  |  ------------------
  |  |  |  |   91|  6.31M|#define ZIP_EF_WINZIP_AES 0x9901
  |  |  ------------------
  |  |               #define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
  |  |  ------------------
  |  |  |  |   92|  3.15M|#define ZIP_EF_ZIP64 0x0001
  |  |  ------------------
  |  |  |  Branch (94:33): [True: 945, False: 3.16M]
  |  |  |  Branch (94:65): [True: 4.08k, False: 3.15M]
  |  |  |  Branch (94:94): [True: 2.94k, False: 3.15M]
  |  |  |  Branch (94:123): [True: 5.63k, False: 3.14M]
  |  |  ------------------
  ------------------
  258|  13.6k|            next = ef->next;
  259|  13.6k|            if (ef_head == ef) {
  ------------------
  |  Branch (259:17): [True: 4.45k, False: 9.14k]
  ------------------
  260|  4.45k|                ef_head = next;
  261|  4.45k|            }
  262|  13.6k|            ef->next = NULL;
  263|  13.6k|            _zip_ef_free(ef);
  264|  13.6k|            if (prev) {
  ------------------
  |  Branch (264:17): [True: 9.14k, False: 4.45k]
  ------------------
  265|  9.14k|                prev->next = next;
  266|  9.14k|            }
  267|  13.6k|            ef = next;
  268|  13.6k|        }
  269|  3.14M|        else {
  270|  3.14M|            prev = ef;
  271|  3.14M|            ef = ef->next;
  272|  3.14M|        }
  273|  3.16M|    }
  274|       |
  275|  74.3k|    return ef_head;
  276|  74.3k|}
_zip_read_local_ef:
  335|   254k|int _zip_read_local_ef(zip_t *za, zip_uint64_t idx) {
  336|   254k|    zip_entry_t *e;
  337|   254k|    unsigned char b[4];
  338|   254k|    zip_buffer_t *buffer;
  339|   254k|    zip_uint16_t fname_len, ef_len;
  340|       |
  341|   254k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (341:9): [True: 0, False: 254k]
  ------------------
  342|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  343|      0|        return -1;
  344|      0|    }
  345|       |
  346|   254k|    e = za->entry + idx;
  347|       |
  348|   254k|    if (e->orig == NULL || e->orig->local_extra_fields_read) {
  ------------------
  |  Branch (348:9): [True: 0, False: 254k]
  |  Branch (348:28): [True: 120k, False: 133k]
  ------------------
  349|   120k|        return 0;
  350|   120k|    }
  351|       |
  352|   133k|    if (e->orig->offset + 26 > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   133k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (352:9): [True: 7, False: 133k]
  ------------------
  353|      7|        zip_error_set(&za->error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      7|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  354|      7|        return -1;
  355|      7|    }
  356|       |
  357|   133k|    if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) {
  ------------------
  |  Branch (357:9): [True: 91.7k, False: 41.7k]
  ------------------
  358|  91.7k|        zip_error_set_from_source(&za->error, za->src);
  359|  91.7k|        return -1;
  360|  91.7k|    }
  361|       |
  362|  41.7k|    if ((buffer = _zip_buffer_new_from_source(za->src, sizeof(b), b, &za->error)) == NULL) {
  ------------------
  |  Branch (362:9): [True: 210, False: 41.5k]
  ------------------
  363|    210|        return -1;
  364|    210|    }
  365|       |
  366|  41.5k|    fname_len = _zip_buffer_get_16(buffer);
  367|  41.5k|    ef_len = _zip_buffer_get_16(buffer);
  368|       |
  369|  41.5k|    if (!_zip_buffer_eof(buffer)) {
  ------------------
  |  Branch (369:9): [True: 0, False: 41.5k]
  ------------------
  370|      0|        _zip_buffer_free(buffer);
  371|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  372|      0|        return -1;
  373|      0|    }
  374|       |
  375|  41.5k|    _zip_buffer_free(buffer);
  376|       |
  377|  41.5k|    if (ef_len > 0) {
  ------------------
  |  Branch (377:9): [True: 38.4k, False: 3.07k]
  ------------------
  378|  38.4k|        zip_extra_field_t *ef;
  379|  38.4k|        zip_uint8_t *ef_raw;
  380|       |
  381|  38.4k|        if (zip_source_seek(za->src, fname_len, SEEK_CUR) < 0) {
  ------------------
  |  Branch (381:13): [True: 0, False: 38.4k]
  ------------------
  382|      0|            zip_error_set(&za->error, ZIP_ER_SEEK, errno);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  383|      0|            return -1;
  384|      0|        }
  385|       |
  386|  38.4k|        ef_raw = _zip_read_data(NULL, za->src, ef_len, 0, &za->error);
  387|       |
  388|  38.4k|        if (ef_raw == NULL) {
  ------------------
  |  Branch (388:13): [True: 9.05k, False: 29.4k]
  ------------------
  389|  9.05k|            return -1;
  390|  9.05k|        }
  391|       |
  392|  29.4k|        if (!_zip_ef_parse(ef_raw, ef_len, ZIP_EF_LOCAL, &ef, &za->error)) {
  ------------------
  |  |  260|  29.4k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  29.4k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (392:13): [True: 27.0k, False: 2.37k]
  ------------------
  393|  27.0k|            free(ef_raw);
  394|  27.0k|            return -1;
  395|  27.0k|        }
  396|  2.37k|        free(ef_raw);
  397|       |
  398|  2.37k|        if (ef) {
  ------------------
  |  Branch (398:13): [True: 1.89k, False: 473]
  ------------------
  399|  1.89k|            ef = _zip_ef_remove_internal(ef);
  400|  1.89k|            e->orig->extra_fields.local = ef;
  401|  1.89k|        }
  402|  2.37k|    }
  403|       |
  404|  5.44k|    e->orig->local_extra_fields_read = 1;
  405|       |
  406|  5.44k|    if (e->changes && e->changes->local_extra_fields_read == 0) {
  ------------------
  |  Branch (406:9): [True: 0, False: 5.44k]
  |  Branch (406:23): [True: 0, False: 0]
  ------------------
  407|      0|        e->changes->extra_fields = e->orig->extra_fields;
  408|      0|        e->changes->local_extra_fields_read = 1;
  409|      0|    }
  410|       |
  411|  5.44k|    return 0;
  412|  41.5k|}
_zip_extra_fields_get_by_id:
  423|   327k|const zip_uint8_t *_zip_extra_fields_get_by_id(const zip_extra_fields_t *extra_fields, zip_uint16_t *lenp, zip_uint16_t extra_field_id, zip_uint16_t extra_field_index, zip_flags_t flags, zip_error_t *error) {
  424|   327k|    const zip_uint8_t *data;
  425|       |
  426|   327k|    if (flags & ZIP_EF_LOCAL) {
  ------------------
  |  |  260|   327k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|   327k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (426:9): [True: 178k, False: 149k]
  ------------------
  427|   178k|        data = _zip_ef_get_by_id(extra_fields->local, lenp, extra_field_id, extra_field_index, flags);
  428|   178k|        if (data) {
  ------------------
  |  Branch (428:13): [True: 553, False: 177k]
  ------------------
  429|    553|            return data;
  430|    553|        }
  431|   178k|    }
  432|       |
  433|   327k|    if (flags & ZIP_EF_CENTRAL) {
  ------------------
  |  |  261|   327k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|   327k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (433:9): [True: 295k, False: 32.1k]
  ------------------
  434|   295k|        data = _zip_ef_get_by_id(extra_fields->central, lenp, extra_field_id, extra_field_index, flags);
  435|   295k|        if (data) {
  ------------------
  |  Branch (435:13): [True: 4.69k, False: 290k]
  ------------------
  436|  4.69k|            return data;
  437|  4.69k|        }
  438|   295k|    }
  439|       |
  440|   322k|    zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|   322k|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  441|       |    return NULL;
  442|   327k|}
_zip_ef_count:
  444|  29.1k|zip_int16_t _zip_ef_count(const zip_extra_field_t *ef, zip_int32_t id) {
  445|  29.1k|    zip_int16_t n;
  446|       |
  447|  29.1k|    n = 0;
  448|  3.16M|    for (; ef; ef = ef->next) {
  ------------------
  |  Branch (448:12): [True: 3.13M, False: 29.1k]
  ------------------
  449|  3.13M|        if (id < 0 || ef->id == id) {
  ------------------
  |  Branch (449:13): [True: 3.13M, False: 0]
  |  Branch (449:23): [True: 0, False: 0]
  ------------------
  450|  3.13M|            n++;
  451|  3.13M|        }
  452|  3.13M|    }
  453|       |
  454|  29.1k|    return n;
  455|  29.1k|}
_zip_extra_fields_count:
  457|  29.1k|zip_int16_t _zip_extra_fields_count(const zip_extra_fields_t *extra_fields, zip_int32_t id, zip_flags_t flags) {
  458|  29.1k|    zip_int16_t n;
  459|       |
  460|  29.1k|    n = 0;
  461|  29.1k|    if (flags & ZIP_EF_LOCAL) {
  ------------------
  |  |  260|  29.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  29.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (461:9): [True: 5.44k, False: 23.7k]
  ------------------
  462|  5.44k|        n += _zip_ef_count(extra_fields->local, id);
  463|  5.44k|    }
  464|  29.1k|    if (flags & ZIP_EF_CENTRAL) {
  ------------------
  |  |  261|  29.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  29.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (464:9): [True: 23.7k, False: 5.44k]
  ------------------
  465|  23.7k|        n += _zip_ef_count(extra_fields->central, id);
  466|  23.7k|    }
  467|       |
  468|  29.1k|    return n;
  469|  29.1k|}
_zip_extra_fields_fini:
  564|  73.3k|void _zip_extra_fields_fini(zip_extra_fields_t *extra_fields) {
  565|  73.3k|    _zip_ef_free(extra_fields->local);
  566|  73.3k|    extra_fields->local = NULL;
  567|  73.3k|    _zip_ef_free(extra_fields->central);
  568|       |    extra_fields->central = NULL;
  569|  73.3k|}
_zip_extra_fields_init:
  571|   219k|void _zip_extra_fields_init(zip_extra_fields_t *extra_fields) {
  572|   219k|    extra_fields->local = NULL;
  573|       |    extra_fields->central = NULL;
  574|   219k|}

zip_file_extra_field_get:
  109|  89.1k|ZIP_EXTERN const zip_uint8_t *zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_uint16_t *idp, zip_uint16_t *lenp, zip_flags_t flags) {
  110|  89.1k|    static const zip_uint8_t empty[1] = {'\0'};
  111|       |
  112|  89.1k|    zip_dirent_t *de;
  113|  89.1k|    zip_extra_field_t *ef;
  114|       |
  115|  89.1k|    if ((flags & ZIP_EF_BOTH) == 0 || ((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH)) {
  ------------------
  |  |  262|  89.1k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  89.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  89.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  89.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  89.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if ((flags & ZIP_EF_BOTH) == 0 || ((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH)) {
  ------------------
  |  |  262|  89.1k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  89.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  89.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  89.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  89.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if ((flags & ZIP_EF_BOTH) == 0 || ((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH)) {
  ------------------
  |  |  262|  89.1k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  89.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  89.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  89.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  89.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (115:9): [True: 0, False: 89.1k]
  |  Branch (115:39): [True: 0, False: 89.1k]
  ------------------
  116|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  117|      0|        return NULL;
  118|      0|    }
  119|       |
  120|  89.1k|    if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 89.1k]
  ------------------
  121|      0|        return NULL;
  122|      0|    }
  123|       |
  124|  89.1k|    if (flags & ZIP_FL_LOCAL) {
  ------------------
  |  |  104|  89.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (124:9): [True: 88.1k, False: 1.04k]
  ------------------
  125|  88.1k|        if (_zip_read_local_ef(za, idx) < 0) {
  ------------------
  |  Branch (125:13): [True: 0, False: 88.1k]
  ------------------
  126|      0|            return NULL;
  127|      0|        }
  128|  88.1k|    }
  129|       |
  130|  89.1k|    ef = (flags & ZIP_FL_LOCAL) ? de->extra_fields.local : de->extra_fields.central;
  ------------------
  |  |  104|  89.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (130:10): [True: 88.1k, False: 1.04k]
  ------------------
  131|  2.79M|    while (ef_idx > 0 && ef) {
  ------------------
  |  Branch (131:12): [True: 2.70M, False: 89.1k]
  |  Branch (131:26): [True: 2.70M, False: 0]
  ------------------
  132|  2.70M|        ef = ef->next;
  133|  2.70M|        ef_idx--;
  134|  2.70M|    }
  135|       |
  136|  89.1k|    if (ef) {
  ------------------
  |  Branch (136:9): [True: 89.1k, False: 0]
  ------------------
  137|  89.1k|        if (idp) {
  ------------------
  |  Branch (137:13): [True: 89.1k, False: 0]
  ------------------
  138|  89.1k|            *idp = ef->id;
  139|  89.1k|        }
  140|  89.1k|        if (lenp) {
  ------------------
  |  Branch (140:13): [True: 89.1k, False: 0]
  ------------------
  141|  89.1k|            *lenp = ef->size;
  142|  89.1k|        }
  143|  89.1k|        if (ef->size > 0) {
  ------------------
  |  Branch (143:13): [True: 3.92k, False: 85.2k]
  ------------------
  144|  3.92k|            return ef->data;
  145|  3.92k|        }
  146|  85.2k|        else {
  147|  85.2k|            return empty;
  148|  85.2k|        }
  149|  89.1k|    }
  150|       |
  151|      0|    zip_error_set(&za->error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|      0|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  152|       |    return NULL;
  153|  89.1k|}
zip_file_extra_field_get_by_id:
  156|   284k|ZIP_EXTERN const zip_uint8_t *zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_uint16_t *lenp, zip_flags_t flags) {
  157|   284k|    zip_dirent_t *de;
  158|       |
  159|   284k|    if ((flags & ZIP_EF_BOTH) == 0) {
  ------------------
  |  |  262|   284k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|   284k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|   284k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|   284k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|   284k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (159:9): [True: 0, False: 284k]
  ------------------
  160|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  161|      0|        return NULL;
  162|      0|    }
  163|       |
  164|   284k|    if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (164:9): [True: 0, False: 284k]
  ------------------
  165|      0|        return NULL;
  166|      0|    }
  167|       |
  168|   284k|    if (flags & ZIP_FL_LOCAL) {
  ------------------
  |  |  104|   284k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (168:9): [True: 142k, False: 142k]
  ------------------
  169|   142k|        if (_zip_read_local_ef(za, idx) < 0) {
  ------------------
  |  Branch (169:13): [True: 109k, False: 32.6k]
  ------------------
  170|   109k|            return NULL;
  171|   109k|        }
  172|   142k|    }
  173|       |
  174|   175k|    return _zip_extra_fields_get_by_id(&de->extra_fields, lenp, ef_id, ef_idx, flags, &za->error);
  175|   284k|}
zip_file_extra_fields_count:
  178|  47.4k|ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) {
  179|  47.4k|    zip_dirent_t *de;
  180|       |
  181|  47.4k|    if ((flags & ZIP_EF_BOTH) == 0) {
  ------------------
  |  |  262|  47.4k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  47.4k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  47.4k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  47.4k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  47.4k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (181:9): [True: 0, False: 47.4k]
  ------------------
  182|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  183|      0|        return -1;
  184|      0|    }
  185|       |
  186|  47.4k|    if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (186:9): [True: 0, False: 47.4k]
  ------------------
  187|      0|        return -1;
  188|      0|    }
  189|       |
  190|  47.4k|    if (flags & ZIP_FL_LOCAL) {
  ------------------
  |  |  104|  47.4k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (190:9): [True: 23.7k, False: 23.7k]
  ------------------
  191|  23.7k|        if (_zip_read_local_ef(za, idx) < 0) {
  ------------------
  |  Branch (191:13): [True: 18.3k, False: 5.44k]
  ------------------
  192|  18.3k|            return -1;
  193|  18.3k|        }
  194|  23.7k|    }
  195|       |
  196|  29.1k|    return _zip_extra_fields_count(&de->extra_fields, -1, flags);
  197|  47.4k|}

zip_file_get_comment:
   39|  23.7k|ZIP_EXTERN const char *zip_file_get_comment(zip_t *za, zip_uint64_t idx, zip_uint32_t *lenp, zip_flags_t flags) {
   40|  23.7k|    zip_dirent_t *de;
   41|  23.7k|    zip_uint32_t len;
   42|  23.7k|    const zip_uint8_t *str;
   43|       |
   44|  23.7k|    if ((de = _zip_get_dirent(za, idx, flags, NULL)) == NULL) {
  ------------------
  |  Branch (44:9): [True: 0, False: 23.7k]
  ------------------
   45|      0|        return NULL;
   46|      0|    }
   47|       |
   48|  23.7k|    if ((str = _zip_string_get(de->comment, &len, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 23.7k]
  ------------------
   49|      0|        return NULL;
   50|      0|    }
   51|       |
   52|  23.7k|    if (lenp) {
  ------------------
  |  Branch (52:9): [True: 23.7k, False: 0]
  ------------------
   53|  23.7k|        *lenp = len;
   54|  23.7k|    }
   55|       |
   56|  23.7k|    return (const char *)str;
   57|  23.7k|}

zip_file_get_external_attributes:
   36|  23.7k|int zip_file_get_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t *opsys, zip_uint32_t *attributes) {
   37|  23.7k|    zip_dirent_t *de;
   38|       |
   39|  23.7k|    if ((de = _zip_get_dirent(za, idx, flags, NULL)) == NULL) {
  ------------------
  |  Branch (39:9): [True: 0, False: 23.7k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|       |
   43|  23.7k|    if (opsys) {
  ------------------
  |  Branch (43:9): [True: 23.7k, False: 0]
  ------------------
   44|  23.7k|        *opsys = (zip_uint8_t)((de->version_madeby >> 8) & 0xff);
   45|  23.7k|    }
   46|       |
   47|  23.7k|    if (attributes) {
  ------------------
  |  Branch (47:9): [True: 23.7k, False: 0]
  ------------------
   48|  23.7k|        *attributes = de->ext_attrib;
   49|  23.7k|    }
   50|       |
   51|  23.7k|    return 0;
   52|  23.7k|}

zip_get_archive_comment:
   40|  1.20k|ZIP_EXTERN const char *zip_get_archive_comment(zip_t *za, int *lenp, zip_flags_t flags) {
   41|  1.20k|    zip_string_t *comment;
   42|  1.20k|    zip_uint32_t len;
   43|  1.20k|    const zip_uint8_t *str;
   44|       |
   45|  1.20k|    if ((flags & ZIP_FL_UNCHANGED) || (za->comment_changes == NULL)) {
  ------------------
  |  |   98|  1.20k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (45:9): [True: 0, False: 1.20k]
  |  Branch (45:39): [True: 1.20k, False: 0]
  ------------------
   46|  1.20k|        comment = za->comment_orig;
   47|  1.20k|    }
   48|      0|    else {
   49|      0|        comment = za->comment_changes;
   50|      0|    }
   51|       |
   52|  1.20k|    if ((str = _zip_string_get(comment, &len, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (52:9): [True: 0, False: 1.20k]
  ------------------
   53|      0|        return NULL;
   54|      0|    }
   55|       |
   56|  1.20k|    if (lenp) {
  ------------------
  |  Branch (56:9): [True: 1.20k, False: 0]
  ------------------
   57|  1.20k|        *lenp = (int)len;
   58|  1.20k|    }
   59|       |
   60|  1.20k|    return (const char *)str;
   61|  1.20k|}

zip_get_name:
   40|  23.7k|ZIP_EXTERN const char *zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags) {
   41|  23.7k|    return _zip_get_name(za, idx, flags, &za->error);
   42|  23.7k|}
_zip_get_name:
   45|  23.7k|const char *_zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
   46|  23.7k|    zip_dirent_t *de;
   47|  23.7k|    const zip_uint8_t *str;
   48|       |
   49|  23.7k|    if ((de = _zip_get_dirent(za, idx, flags, error)) == NULL) {
  ------------------
  |  Branch (49:9): [True: 0, False: 23.7k]
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|       |
   53|  23.7k|    if ((str = _zip_string_get(de->filename, NULL, flags, error)) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 23.7k]
  ------------------
   54|      0|        return NULL;
   55|      0|    }
   56|       |
   57|  23.7k|    return (const char *)str;
   58|  23.7k|}

zip_get_num_entries:
   38|  1.20k|ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *za, zip_flags_t flags) {
   39|  1.20k|    zip_uint64_t n;
   40|       |
   41|  1.20k|    if (za == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 1.20k]
  ------------------
   42|      0|        return -1;
   43|      0|    }
   44|       |
   45|  1.20k|    if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|  1.20k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (45:9): [True: 0, False: 1.20k]
  ------------------
   46|      0|        n = za->nentry;
   47|      0|        while (n > 0 && za->entry[n - 1].orig == NULL) {
  ------------------
  |  Branch (47:16): [True: 0, False: 0]
  |  Branch (47:25): [True: 0, False: 0]
  ------------------
   48|      0|            --n;
   49|      0|        }
   50|      0|        return (zip_int64_t)n;
   51|      0|    }
   52|  1.20k|    return (zip_int64_t)za->nentry;
   53|  1.20k|}

_zip_hash_new:
  162|  3.72k|zip_hash_t *_zip_hash_new(zip_error_t *error) {
  163|  3.72k|    zip_hash_t *hash;
  164|       |
  165|  3.72k|    if ((hash = (zip_hash_t *)malloc(sizeof(zip_hash_t))) == NULL) {
  ------------------
  |  Branch (165:9): [True: 0, False: 3.72k]
  ------------------
  166|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  167|      0|        return NULL;
  168|      0|    }
  169|       |
  170|  3.72k|    hash->table_size = 0;
  171|  3.72k|    hash->nentries = 0;
  172|  3.72k|    hash->table = NULL;
  173|       |
  174|  3.72k|    return hash;
  175|  3.72k|}
_zip_hash_free:
  178|  3.72k|void _zip_hash_free(zip_hash_t *hash) {
  179|  3.72k|    zip_uint32_t i;
  180|       |
  181|  3.72k|    if (hash == NULL) {
  ------------------
  |  Branch (181:9): [True: 0, False: 3.72k]
  ------------------
  182|      0|        return;
  183|      0|    }
  184|       |
  185|  3.72k|    if (hash->table != NULL) {
  ------------------
  |  Branch (185:9): [True: 720, False: 3.00k]
  ------------------
  186|  48.2k|        for (i = 0; i < hash->table_size; i++) {
  ------------------
  |  Branch (186:21): [True: 47.4k, False: 720]
  ------------------
  187|  47.4k|            if (hash->table[i] != NULL) {
  ------------------
  |  Branch (187:17): [True: 9.76k, False: 37.7k]
  ------------------
  188|  9.76k|                free_list(hash->table[i]);
  189|  9.76k|            }
  190|  47.4k|        }
  191|    720|        free(hash->table);
  192|    720|    }
  193|  3.72k|    free(hash);
  194|  3.72k|}
_zip_hash_add:
  198|  23.7k|bool _zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error) {
  199|  23.7k|    zip_uint32_t hash_value, table_index;
  200|  23.7k|    zip_hash_entry_t *entry;
  201|       |
  202|  23.7k|    if (hash == NULL || name == NULL || index > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  23.7k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (202:9): [True: 0, False: 23.7k]
  |  Branch (202:25): [True: 0, False: 23.7k]
  |  Branch (202:41): [True: 0, False: 23.7k]
  ------------------
  203|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  204|      0|        return false;
  205|      0|    }
  206|       |
  207|  23.7k|    if (hash->table_size == 0) {
  ------------------
  |  Branch (207:9): [True: 0, False: 23.7k]
  ------------------
  208|      0|        if (!hash_resize(hash, HASH_MIN_SIZE, error)) {
  ------------------
  |  |   47|      0|#define HASH_MIN_SIZE 256
  ------------------
  |  Branch (208:13): [True: 0, False: 0]
  ------------------
  209|      0|            return false;
  210|      0|        }
  211|      0|    }
  212|       |
  213|  23.7k|    hash_value = hash_string(name);
  214|  23.7k|    table_index = hash_value % hash->table_size;
  215|       |
  216|  29.2k|    for (entry = hash->table[table_index]; entry != NULL; entry = entry->next) {
  ------------------
  |  Branch (216:44): [True: 15.2k, False: 14.0k]
  ------------------
  217|  15.2k|        if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
  ------------------
  |  Branch (217:13): [True: 9.91k, False: 5.31k]
  |  Branch (217:48): [True: 9.68k, False: 224]
  ------------------
  218|  9.68k|            if (((flags & ZIP_FL_UNCHANGED) && entry->orig_index != -1) || entry->current_index != -1) {
  ------------------
  |  |   98|  9.68k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (218:18): [True: 9.68k, False: 0]
  |  Branch (218:48): [True: 9.68k, False: 0]
  |  Branch (218:76): [True: 0, False: 0]
  ------------------
  219|  9.68k|                zip_error_set(error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|  9.68k|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
  220|  9.68k|                return false;
  221|  9.68k|            }
  222|      0|            else {
  223|      0|                break;
  224|      0|            }
  225|  9.68k|        }
  226|  15.2k|    }
  227|       |
  228|  14.0k|    if (entry == NULL) {
  ------------------
  |  Branch (228:9): [True: 14.0k, False: 0]
  ------------------
  229|  14.0k|        if ((entry = (zip_hash_entry_t *)malloc(sizeof(zip_hash_entry_t))) == NULL) {
  ------------------
  |  Branch (229:13): [True: 0, False: 14.0k]
  ------------------
  230|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  231|      0|            return false;
  232|      0|        }
  233|  14.0k|        entry->name = name;
  234|  14.0k|        entry->next = hash->table[table_index];
  235|  14.0k|        hash->table[table_index] = entry;
  236|  14.0k|        entry->hash_value = hash_value;
  237|  14.0k|        entry->orig_index = -1;
  238|  14.0k|        hash->nentries++;
  239|  14.0k|        if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
  ------------------
  |  |   43|  28.1k|#define HASH_MAX_FILL .75
  ------------------
                      if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
  ------------------
  |  |   48|    494|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  |  Branch (239:13): [True: 494, False: 13.5k]
  |  Branch (239:66): [True: 494, False: 0]
  ------------------
  240|    494|            if (!hash_resize(hash, hash->table_size * 2, error)) {
  ------------------
  |  Branch (240:17): [True: 0, False: 494]
  ------------------
  241|      0|                return false;
  242|      0|            }
  243|    494|        }
  244|  14.0k|    }
  245|       |
  246|  14.0k|    if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|  14.0k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (246:9): [True: 14.0k, False: 0]
  ------------------
  247|  14.0k|        entry->orig_index = (zip_int64_t)index;
  248|  14.0k|    }
  249|  14.0k|    entry->current_index = (zip_int64_t)index;
  250|       |
  251|       |    return true;
  252|  14.0k|}
_zip_hash_reserve_capacity:
  337|  1.20k|bool _zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error) {
  338|  1.20k|    zip_uint32_t new_size;
  339|       |
  340|  1.20k|    if (capacity == 0) {
  ------------------
  |  Branch (340:9): [True: 483, False: 720]
  ------------------
  341|    483|        return true;
  342|    483|    }
  343|       |
  344|    720|    new_size = size_for_capacity(capacity);
  345|       |
  346|    720|    if (new_size <= hash->table_size) {
  ------------------
  |  Branch (346:9): [True: 0, False: 720]
  ------------------
  347|      0|        return true;
  348|      0|    }
  349|       |
  350|    720|    if (!hash_resize(hash, new_size, error)) {
  ------------------
  |  Branch (350:9): [True: 0, False: 720]
  ------------------
  351|      0|        return false;
  352|      0|    }
  353|       |
  354|    720|    return true;
  355|    720|}
zip_hash.c:free_list:
   67|  9.76k|static void free_list(zip_hash_entry_t *entry) {
   68|  23.8k|    while (entry != NULL) {
  ------------------
  |  Branch (68:12): [True: 14.0k, False: 9.76k]
  ------------------
   69|  14.0k|        zip_hash_entry_t *next = entry->next;
   70|  14.0k|        free(entry);
   71|  14.0k|        entry = next;
   72|  14.0k|    }
   73|  9.76k|}
zip_hash.c:hash_resize:
   94|  1.21k|static bool hash_resize(zip_hash_t *hash, zip_uint32_t new_size, zip_error_t *error) {
   95|  1.21k|    zip_hash_entry_t **new_table;
   96|       |
   97|  1.21k|    if (new_size == hash->table_size) {
  ------------------
  |  Branch (97:9): [True: 0, False: 1.21k]
  ------------------
   98|      0|        return true;
   99|      0|    }
  100|       |
  101|  1.21k|    if ((new_table = (zip_hash_entry_t **)calloc(new_size, sizeof(zip_hash_entry_t *))) == NULL) {
  ------------------
  |  Branch (101:9): [True: 0, False: 1.21k]
  ------------------
  102|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  103|      0|        return false;
  104|      0|    }
  105|       |
  106|  1.21k|    if (hash->nentries > 0) {
  ------------------
  |  Branch (106:9): [True: 494, False: 720]
  ------------------
  107|    494|        zip_uint32_t i;
  108|       |
  109|  1.03k|        for (i = 0; i < hash->table_size; i++) {
  ------------------
  |  Branch (109:21): [True: 542, False: 494]
  ------------------
  110|    542|            zip_hash_entry_t *entry = hash->table[i];
  111|  1.08k|            while (entry) {
  ------------------
  |  Branch (111:20): [True: 542, False: 542]
  ------------------
  112|    542|                zip_hash_entry_t *next = entry->next;
  113|       |
  114|    542|                zip_uint32_t new_index = entry->hash_value % new_size;
  115|       |
  116|    542|                entry->next = new_table[new_index];
  117|    542|                new_table[new_index] = entry;
  118|       |
  119|    542|                entry = next;
  120|    542|            }
  121|    542|        }
  122|    494|    }
  123|       |
  124|  1.21k|    free(hash->table);
  125|  1.21k|    hash->table = new_table;
  126|  1.21k|    hash->table_size = new_size;
  127|       |
  128|       |    return true;
  129|  1.21k|}
zip_hash.c:hash_string:
   77|  23.7k|static zip_uint32_t hash_string(const zip_uint8_t *name) {
   78|  23.7k|    zip_uint64_t value = HASH_START;
  ------------------
  |  |   40|  23.7k|#define HASH_START 5381
  ------------------
   79|       |
   80|  23.7k|    if (name == NULL) {
  ------------------
  |  Branch (80:9): [True: 0, False: 23.7k]
  ------------------
   81|      0|        return 0;
   82|      0|    }
   83|       |
   84|   133k|    while (*name != 0) {
  ------------------
  |  Branch (84:12): [True: 109k, False: 23.7k]
  ------------------
   85|   109k|        value = (zip_uint64_t)(((value * HASH_MULTIPLIER) + (zip_uint8_t)*name) % 0x100000000ul);
  ------------------
  |  |   39|   109k|#define HASH_MULTIPLIER 33
  ------------------
   86|   109k|        name++;
   87|   109k|    }
   88|       |
   89|  23.7k|    return (zip_uint32_t)value;
   90|  23.7k|}
zip_hash.c:size_for_capacity:
  132|    720|static zip_uint32_t size_for_capacity(zip_uint64_t capacity) {
  133|    720|    double needed_size = capacity / HASH_MAX_FILL;
  ------------------
  |  |   43|    720|#define HASH_MAX_FILL .75
  ------------------
  134|    720|    zip_uint32_t v;
  135|       |
  136|    720|    if (needed_size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    720|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (136:9): [True: 0, False: 720]
  ------------------
  137|      0|        v = ZIP_UINT32_MAX;
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  138|      0|    }
  139|    720|    else {
  140|    720|        v = (zip_uint32_t)needed_size;
  141|    720|    }
  142|       |
  143|    720|    if (v > HASH_MAX_SIZE) {
  ------------------
  |  |   48|    720|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  |  Branch (143:9): [True: 0, False: 720]
  ------------------
  144|      0|        return HASH_MAX_SIZE;
  ------------------
  |  |   48|      0|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  145|      0|    }
  146|       |
  147|       |    /* From Bit Twiddling Hacks by Sean Eron Anderson <seander@cs.stanford.edu>
  148|       |     (http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2). */
  149|       |
  150|    720|    v--;
  151|    720|    v |= v >> 1;
  152|    720|    v |= v >> 2;
  153|    720|    v |= v >> 4;
  154|    720|    v |= v >> 8;
  155|    720|    v |= v >> 16;
  156|    720|    v++;
  157|       |
  158|    720|    return v;
  159|    720|}

_zip_read:
   41|   195k|int _zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error) {
   42|   195k|    zip_int64_t n;
   43|       |
   44|   195k|    if (length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   195k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (44:9): [True: 0, False: 195k]
  ------------------
   45|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|   195k|    if ((n = zip_source_read(src, b, length)) < 0) {
  ------------------
  |  Branch (49:9): [True: 0, False: 195k]
  ------------------
   50|      0|        zip_error_set_from_source(error, src);
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|   195k|    if (n < (zip_int64_t)length) {
  ------------------
  |  Branch (54:9): [True: 9.29k, False: 186k]
  ------------------
   55|  9.29k|        zip_error_set(error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|  9.29k|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
   56|  9.29k|        return -1;
   57|  9.29k|    }
   58|       |
   59|   186k|    return 0;
   60|   195k|}
_zip_read_data:
   63|   114k|zip_uint8_t *_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error) {
   64|   114k|    zip_uint8_t *r;
   65|       |
   66|   114k|    if (length == 0 && !nulp) {
  ------------------
  |  Branch (66:9): [True: 0, False: 114k]
  |  Branch (66:24): [True: 0, False: 0]
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|   114k|    r = (zip_uint8_t *)malloc(length + (nulp ? 1 : 0));
  ------------------
  |  Branch (70:41): [True: 63.7k, False: 50.9k]
  ------------------
   71|   114k|    if (r == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 114k]
  ------------------
   72|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   73|      0|        return NULL;
   74|      0|    }
   75|       |
   76|   114k|    if (buffer) {
  ------------------
  |  Branch (76:9): [True: 76.2k, False: 38.4k]
  ------------------
   77|  76.2k|        zip_uint8_t *data = _zip_buffer_get(buffer, length);
   78|       |
   79|  76.2k|        if (data == NULL) {
  ------------------
  |  Branch (79:13): [True: 0, False: 76.2k]
  ------------------
   80|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   81|      0|            free(r);
   82|      0|            return NULL;
   83|      0|        }
   84|  76.2k|        (void)memcpy_s(r, length, data, length);
  ------------------
  |  |  202|  76.2k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
   85|  76.2k|    }
   86|  38.4k|    else {
   87|  38.4k|        if (_zip_read(src, r, length, error) < 0) {
  ------------------
  |  Branch (87:13): [True: 9.05k, False: 29.4k]
  ------------------
   88|  9.05k|            free(r);
   89|  9.05k|            return NULL;
   90|  9.05k|        }
   91|  38.4k|    }
   92|       |
   93|   105k|    if (nulp) {
  ------------------
  |  Branch (93:9): [True: 63.7k, False: 41.8k]
  ------------------
   94|  63.7k|        r[length] = 0;
   95|  63.7k|    }
   96|       |
   97|   105k|    return r;
   98|   114k|}
_zip_read_string:
  101|  70.3k|zip_string_t *_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t len, bool nulp, zip_error_t *error) {
  102|  70.3k|    zip_uint8_t *raw;
  103|  70.3k|    zip_string_t *s;
  104|       |
  105|  70.3k|    if ((raw = _zip_read_data(buffer, src, len, nulp, error)) == NULL) {
  ------------------
  |  Branch (105:9): [True: 0, False: 70.3k]
  ------------------
  106|      0|        return NULL;
  107|      0|    }
  108|       |
  109|  70.3k|    s = _zip_string_new(raw, len, ZIP_FL_ENC_GUESS, error);
  ------------------
  |  |  101|  70.3k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  110|  70.3k|    free(raw);
  111|  70.3k|    return s;
  112|  70.3k|}

_zip_memdup:
   40|   180k|void *_zip_memdup(const void *mem, size_t len, zip_error_t *error) {
   41|   180k|    void *ret;
   42|       |
   43|   180k|    if (len == 0) {
  ------------------
  |  Branch (43:9): [True: 0, False: 180k]
  ------------------
   44|      0|        return NULL;
   45|      0|    }
   46|       |
   47|   180k|    ret = malloc(len);
   48|   180k|    if (ret == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 180k]
  ------------------
   49|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|       |
   53|   180k|    (void)memcpy_s(ret, len, mem, len);
  ------------------
  |  |  202|   180k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
   54|       |
   55|   180k|    return ret;
   56|   180k|}

_zip_new:
   44|  3.72k|zip_t *_zip_new(zip_error_t *error) {
   45|  3.72k|    zip_t *za;
   46|       |
   47|  3.72k|    za = (zip_t *)malloc(sizeof(struct zip));
   48|  3.72k|    if (za == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 3.72k]
  ------------------
   49|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|       |
   53|  3.72k|    if ((za->names = _zip_hash_new(error)) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 3.72k]
  ------------------
   54|      0|        free(za);
   55|      0|        return NULL;
   56|      0|    }
   57|       |
   58|  3.72k|    za->src = NULL;
   59|  3.72k|    za->open_flags = 0;
   60|  3.72k|    zip_error_init(&za->error);
   61|  3.72k|    za->flags = za->ch_flags = 0;
   62|  3.72k|    za->default_password = NULL;
   63|  3.72k|    za->comment_orig = za->comment_changes = NULL;
   64|  3.72k|    za->comment_changed = 0;
   65|  3.72k|    za->nentry = za->nentry_alloc = 0;
   66|  3.72k|    za->entry = NULL;
   67|  3.72k|    za->nopen_source = za->nopen_source_alloc = 0;
   68|  3.72k|    za->open_source = NULL;
   69|  3.72k|    za->progress = NULL;
   70|  3.72k|    za->torrent_mtime = 0;
   71|       |
   72|  3.72k|    return za;
   73|  3.72k|}

zip_open_from_source:
   91|  3.72k|ZIP_EXTERN zip_t *zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
   92|  3.72k|    unsigned int flags;
   93|  3.72k|    zip_int64_t supported;
   94|  3.72k|    exists_t exists;
   95|       |
   96|  3.72k|    if (_flags < 0 || src == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 3.72k]
  |  Branch (96:23): [True: 0, False: 3.72k]
  ------------------
   97|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   98|      0|        return NULL;
   99|      0|    }
  100|  3.72k|    flags = (unsigned int)_flags;
  101|       |
  102|  3.72k|    supported = zip_source_supports(src);
  103|  3.72k|    if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
  ------------------
  |  |  289|  3.72k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|  3.72k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
  ------------------
  |  |  289|  3.72k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|  3.72k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  |  Branch (103:9): [True: 0, False: 3.72k]
  ------------------
  104|      0|        zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
  105|      0|        return NULL;
  106|      0|    }
  107|  3.72k|    if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
  ------------------
  |  |  294|  3.72k|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  289|  3.72k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  282|  3.72k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  287|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  290|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  292|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  295|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  301|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
  ------------------
  |  |  294|  3.72k|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  289|  3.72k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  282|  3.72k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  287|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  290|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  292|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  295|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  301|  3.72k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  276|  3.72k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  |  Branch (107:9): [True: 0, False: 3.72k]
  ------------------
  108|      0|        flags |= ZIP_RDONLY;
  ------------------
  |  |   90|      0|#define ZIP_RDONLY 16
  ------------------
  109|      0|    }
  110|       |
  111|  3.72k|    if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   90|  3.72k|#define ZIP_RDONLY 16
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   89|  3.72k|#define ZIP_TRUNCATE 8
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   90|  3.72k|#define ZIP_RDONLY 16
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   89|  3.72k|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (111:9): [True: 0, False: 3.72k]
  ------------------
  112|      0|        zip_error_set(error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
  113|      0|        return NULL;
  114|      0|    }
  115|       |
  116|  3.72k|    exists = _zip_file_exists(src, error);
  117|  3.72k|    switch (exists) {
  118|      0|    case EXISTS_ERROR:
  ------------------
  |  Branch (118:5): [True: 0, False: 3.72k]
  ------------------
  119|      0|        return NULL;
  120|       |
  121|      0|    case EXISTS_NOT:
  ------------------
  |  Branch (121:5): [True: 0, False: 3.72k]
  ------------------
  122|      0|        if ((flags & ZIP_CREATE) == 0) {
  ------------------
  |  |   86|      0|#define ZIP_CREATE 1
  ------------------
  |  Branch (122:13): [True: 0, False: 0]
  ------------------
  123|      0|            zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|      0|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  124|      0|            return NULL;
  125|      0|        }
  126|      0|        return _zip_allocate_new(src, flags, error);
  127|       |
  128|  3.72k|    default: {
  ------------------
  |  Branch (128:5): [True: 3.72k, False: 0]
  ------------------
  129|  3.72k|        zip_t *za;
  130|  3.72k|        if (flags & ZIP_EXCL) {
  ------------------
  |  |   87|  3.72k|#define ZIP_EXCL 2
  ------------------
  |  Branch (130:13): [True: 0, False: 3.72k]
  ------------------
  131|      0|            zip_error_set(error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
  132|      0|            return NULL;
  133|      0|        }
  134|  3.72k|        if (zip_source_open(src) < 0) {
  ------------------
  |  Branch (134:13): [True: 0, False: 3.72k]
  ------------------
  135|      0|            zip_error_set_from_source(error, src);
  136|      0|            return NULL;
  137|      0|        }
  138|       |
  139|  3.72k|        if (flags & ZIP_TRUNCATE) {
  ------------------
  |  |   89|  3.72k|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (139:13): [True: 0, False: 3.72k]
  ------------------
  140|      0|            za = _zip_allocate_new(src, flags, error);
  141|      0|        }
  142|  3.72k|        else {
  143|       |            /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL, just like open() */
  144|  3.72k|            za = _zip_open(src, flags, error);
  145|  3.72k|        }
  146|       |
  147|  3.72k|        if (za == NULL) {
  ------------------
  |  Branch (147:13): [True: 2.51k, False: 1.20k]
  ------------------
  148|  2.51k|            zip_source_close(src);
  149|  2.51k|            return NULL;
  150|  2.51k|        }
  151|  1.20k|        return za;
  152|  3.72k|    }
  153|  3.72k|    }
  154|  3.72k|}
_zip_open:
  177|  3.72k|zip_t *_zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error) {
  178|  3.72k|    zip_t *za;
  179|  3.72k|    zip_cdir_t *cdir;
  180|  3.72k|    struct zip_stat st;
  181|  3.72k|    zip_uint64_t len, idx;
  182|       |
  183|  3.72k|    zip_stat_init(&st);
  184|  3.72k|    if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (184:9): [True: 0, False: 3.72k]
  ------------------
  185|      0|        zip_error_set_from_source(error, src);
  186|      0|        return NULL;
  187|      0|    }
  188|  3.72k|    if ((st.valid & ZIP_STAT_SIZE) == 0) {
  ------------------
  |  |  325|  3.72k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (188:9): [True: 0, False: 3.72k]
  ------------------
  189|      0|        zip_error_set(error, ZIP_ER_SEEK, EOPNOTSUPP);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  190|      0|        return NULL;
  191|      0|    }
  192|  3.72k|    len = st.size;
  193|       |
  194|       |
  195|  3.72k|    if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
  ------------------
  |  Branch (195:9): [True: 0, False: 3.72k]
  ------------------
  196|      0|        return NULL;
  197|      0|    }
  198|       |
  199|       |    /* treat empty files as empty archives */
  200|  3.72k|    if (len == 0 && zip_source_accept_empty(src)) {
  ------------------
  |  Branch (200:9): [True: 0, False: 3.72k]
  |  Branch (200:21): [True: 0, False: 0]
  ------------------
  201|      0|        return za;
  202|      0|    }
  203|       |
  204|  3.72k|    if ((cdir = _zip_find_central_dir(za, len)) == NULL) {
  ------------------
  |  Branch (204:9): [True: 2.51k, False: 1.20k]
  ------------------
  205|  2.51k|        _zip_error_copy(error, &za->error);
  206|  2.51k|        if (zip_error_code_zip(&za->error) == ZIP_ER_NOZIP) {
  ------------------
  |  |  150|  2.51k|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  |  Branch (206:13): [True: 575, False: 1.94k]
  ------------------
  207|       |            /* not a zip - find out if it's truncated */
  208|    575|            if (_is_truncated_zip(src)) {
  ------------------
  |  Branch (208:17): [True: 3, False: 572]
  ------------------
  209|      3|                zip_error_set(error, ZIP_ER_TRUNCATED_ZIP, 0);
  ------------------
  |  |  166|      3|#define ZIP_ER_TRUNCATED_ZIP 35   /* N Possibly truncated or corrupted zip archive */
  ------------------
  210|      3|            }
  211|    575|        }
  212|       |        /* keep src so discard does not get rid of it */
  213|  2.51k|        zip_source_keep(src);
  214|  2.51k|        zip_discard(za);
  215|  2.51k|        return NULL;
  216|  2.51k|    }
  217|       |
  218|  1.20k|    za->entry = cdir->entry;
  219|  1.20k|    za->nentry = cdir->nentry;
  220|  1.20k|    za->nentry_alloc = cdir->nentry_alloc;
  221|       |
  222|  1.20k|    zip_check_torrentzip(za, cdir);
  223|       |
  224|  1.20k|    if (ZIP_IS_TORRENTZIP(za)) {
  ------------------
  |  |  522|  1.20k|#define ZIP_IS_TORRENTZIP(za) ((za)->flags & ZIP_AFL_IS_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  114|  1.20k|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  |  |  ------------------
  |  |  |  Branch (522:31): [True: 1, False: 1.20k]
  |  |  ------------------
  ------------------
  225|       |        /* Torrentzip uses the archive comment to detect changes by tools that are not torrentzip aware. */
  226|      1|        _zip_string_free(cdir->comment);
  227|      1|    }
  228|  1.20k|    else {
  229|  1.20k|        za->comment_orig = cdir->comment;
  230|  1.20k|    }
  231|       |
  232|  1.20k|    free(cdir);
  233|       |
  234|  1.20k|    _zip_hash_reserve_capacity(za->names, za->nentry, &za->error);
  235|       |
  236|  24.9k|    for (idx = 0; idx < za->nentry; idx++) {
  ------------------
  |  Branch (236:19): [True: 23.7k, False: 1.20k]
  ------------------
  237|  23.7k|        const zip_uint8_t *name = _zip_string_get(za->entry[idx].orig->filename, NULL, 0, error);
  238|  23.7k|        if (name == NULL) {
  ------------------
  |  Branch (238:13): [True: 0, False: 23.7k]
  ------------------
  239|       |            /* keep src so discard does not get rid of it */
  240|      0|            zip_source_keep(src);
  241|      0|            zip_discard(za);
  242|      0|            return NULL;
  243|      0|        }
  244|       |
  245|  23.7k|        if (_zip_hash_add(za->names, name, idx, ZIP_FL_UNCHANGED, &za->error) == false) {
  ------------------
  |  |   98|  23.7k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (245:13): [True: 9.68k, False: 14.0k]
  ------------------
  246|  9.68k|            if (za->error.zip_err != ZIP_ER_EXISTS || (flags & ZIP_CHECKCONS)) {
  ------------------
  |  |  141|  19.3k|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
                          if (za->error.zip_err != ZIP_ER_EXISTS || (flags & ZIP_CHECKCONS)) {
  ------------------
  |  |   88|  9.68k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (246:17): [True: 0, False: 9.68k]
  |  Branch (246:55): [True: 0, False: 9.68k]
  ------------------
  247|      0|                _zip_error_copy(error, &za->error);
  248|       |                /* keep src so discard does not get rid of it */
  249|      0|                zip_source_keep(src);
  250|      0|                zip_discard(za);
  251|      0|                return NULL;
  252|      0|            }
  253|  9.68k|        }
  254|  23.7k|    }
  255|       |
  256|  1.20k|    za->ch_flags = za->flags;
  257|       |
  258|  1.20k|    return za;
  259|  1.20k|}
zip_open.c:_is_truncated_zip:
  157|    575|static bool _is_truncated_zip(zip_source_t *src) {
  158|    575|    unsigned char data[4];
  159|       |    /* check if the source is a truncated zip archive: true if yes, no
  160|       |       if not or can't be determined */
  161|    575|    if (zip_source_seek(src, 0, SEEK_SET) < 0) {
  ------------------
  |  Branch (161:9): [True: 0, False: 575]
  ------------------
  162|      0|        return false;
  163|      0|    }
  164|       |
  165|    575|    if (zip_source_read(src, data, 4) != 4) {
  ------------------
  |  Branch (165:9): [True: 3, False: 572]
  ------------------
  166|      3|        return false;
  167|      3|    }
  168|       |
  169|    572|    if (memcmp(data, LOCAL_MAGIC, 4) == 0) {
  ------------------
  |  |   52|    572|#define LOCAL_MAGIC "PK\3\4"
  ------------------
  |  Branch (169:9): [True: 3, False: 569]
  ------------------
  170|       |        /* file starts with a ZIP local header signature */
  171|      3|        return true;
  172|      3|    }
  173|    569|    return false;
  174|    572|}
zip_open.c:_zip_allocate_new:
  643|  3.72k|static zip_t *_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error) {
  644|  3.72k|    zip_t *za;
  645|       |
  646|  3.72k|    if ((za = _zip_new(error)) == NULL) {
  ------------------
  |  Branch (646:9): [True: 0, False: 3.72k]
  ------------------
  647|      0|        return NULL;
  648|      0|    }
  649|       |
  650|  3.72k|    za->src = src;
  651|  3.72k|    za->open_flags = flags;
  652|  3.72k|    za->flags = 0;
  653|  3.72k|    za->ch_flags = 0;
  654|  3.72k|    za->write_crc = NULL;
  655|       |
  656|  3.72k|    if (flags & ZIP_RDONLY) {
  ------------------
  |  |   90|  3.72k|#define ZIP_RDONLY 16
  ------------------
  |  Branch (656:9): [True: 3.72k, False: 0]
  ------------------
  657|  3.72k|        za->flags |= ZIP_AFL_RDONLY;
  ------------------
  |  |  113|  3.72k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  ------------------
  658|  3.72k|        za->ch_flags |= ZIP_AFL_RDONLY;
  ------------------
  |  |  113|  3.72k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  ------------------
  659|  3.72k|    }
  660|       |
  661|  3.72k|    return za;
  662|  3.72k|}
zip_open.c:_zip_file_exists:
  668|  3.72k|static exists_t _zip_file_exists(zip_source_t *src, zip_error_t *error) {
  669|  3.72k|    struct zip_stat st;
  670|       |
  671|  3.72k|    zip_stat_init(&st);
  672|  3.72k|    if (zip_source_stat(src, &st) != 0) {
  ------------------
  |  Branch (672:9): [True: 0, False: 3.72k]
  ------------------
  673|      0|        zip_error_t *src_error = zip_source_error(src);
  674|      0|        if (zip_error_code_zip(src_error) == ZIP_ER_READ && zip_error_code_system(src_error) == ENOENT) {
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  |  Branch (674:13): [True: 0, False: 0]
  |  Branch (674:61): [True: 0, False: 0]
  ------------------
  675|      0|            return EXISTS_NOT;
  676|      0|        }
  677|      0|        _zip_error_copy(error, src_error);
  678|      0|        return EXISTS_ERROR;
  679|      0|    }
  680|       |
  681|  3.72k|    return EXISTS_OK;
  682|  3.72k|}
zip_open.c:_zip_find_central_dir:
  685|  3.72k|static zip_cdir_t *_zip_find_central_dir(zip_t *za, zip_uint64_t len) {
  686|  3.72k|    zip_cdir_t *cdir;
  687|  3.72k|    const zip_uint8_t *match;
  688|  3.72k|    zip_int64_t buf_offset;
  689|  3.72k|    zip_uint64_t buflen;
  690|  3.72k|    zip_error_t error;
  691|  3.72k|    zip_buffer_t *buffer;
  692|       |
  693|  3.72k|    if (len < EOCDLEN) {
  ------------------
  |  |   62|  3.72k|#define EOCDLEN 22
  ------------------
  |  Branch (693:9): [True: 46, False: 3.67k]
  ------------------
  694|     46|        zip_error_set(&za->error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|     46|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  695|     46|        return NULL;
  696|     46|    }
  697|       |
  698|  3.67k|    buflen = (len < CDBUFSIZE ? len : CDBUFSIZE);
  ------------------
  |  |   65|  3.67k|#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   60|  3.67k|#define MAXCOMLEN 65536
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   62|  3.67k|#define EOCDLEN 22
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   63|  3.67k|#define EOCD64LOCLEN 20
  |  |  ------------------
  ------------------
                  buflen = (len < CDBUFSIZE ? len : CDBUFSIZE);
  ------------------
  |  |   65|    221|#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   60|    221|#define MAXCOMLEN 65536
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   62|    221|#define EOCDLEN 22
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   63|    221|#define EOCD64LOCLEN 20
  |  |  ------------------
  ------------------
  |  Branch (698:15): [True: 3.45k, False: 221]
  ------------------
  699|  3.67k|    if (zip_source_seek(za->src, -(zip_int64_t)buflen, SEEK_END) < 0) {
  ------------------
  |  Branch (699:9): [True: 0, False: 3.67k]
  ------------------
  700|      0|        zip_error_t *src_error = zip_source_error(za->src);
  701|      0|        if (zip_error_code_zip(src_error) != ZIP_ER_SEEK || zip_error_code_system(src_error) != EFBIG) {
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  |  Branch (701:13): [True: 0, False: 0]
  |  Branch (701:61): [True: 0, False: 0]
  ------------------
  702|       |            /* seek before start of file on my machine */
  703|      0|            _zip_error_copy(&za->error, src_error);
  704|      0|            return NULL;
  705|      0|        }
  706|      0|    }
  707|  3.67k|    if ((buf_offset = zip_source_tell(za->src)) < 0) {
  ------------------
  |  Branch (707:9): [True: 0, False: 3.67k]
  ------------------
  708|      0|        zip_error_set_from_source(&za->error, za->src);
  709|      0|        return NULL;
  710|      0|    }
  711|       |
  712|  3.67k|    if ((buffer = _zip_buffer_new_from_source(za->src, buflen, NULL, &za->error)) == NULL) {
  ------------------
  |  Branch (712:9): [True: 0, False: 3.67k]
  ------------------
  713|      0|        return NULL;
  714|      0|    }
  715|       |
  716|  3.67k|    cdir = NULL;
  717|  3.67k|    if (buflen >= CDBUFSIZE) {
  ------------------
  |  |   65|  3.67k|#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   60|  3.67k|#define MAXCOMLEN 65536
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   62|  3.67k|#define EOCDLEN 22
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   63|  3.67k|#define EOCD64LOCLEN 20
  |  |  ------------------
  ------------------
  |  Branch (717:9): [True: 221, False: 3.45k]
  ------------------
  718|       |        /* EOCD64 locator is before EOCD, so leave place for it */
  719|    221|        _zip_buffer_set_offset(buffer, EOCD64LOCLEN);
  ------------------
  |  |   63|    221|#define EOCD64LOCLEN 20
  ------------------
  720|    221|    }
  721|  3.67k|    zip_error_set(&error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|  3.67k|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  722|       |
  723|  3.67k|    match = NULL;
  724|  26.3k|    while ((match = find_eocd(buffer, match)) != NULL) {
  ------------------
  |  Branch (724:12): [True: 25.9k, False: 428]
  ------------------
  725|  25.9k|        _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
  726|  25.9k|        if (_zip_read_cdir(za, buffer, (zip_uint64_t)buf_offset, &cdir, &error)) {
  ------------------
  |  Branch (726:13): [True: 3.24k, False: 22.6k]
  ------------------
  727|  3.24k|            if (cdir != NULL && (za->open_flags & ZIP_CHECKCONS) && _zip_checkcons(za, cdir, &error) < 0) {
  ------------------
  |  |   88|  1.20k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (727:17): [True: 1.20k, False: 2.04k]
  |  Branch (727:33): [True: 0, False: 1.20k]
  |  Branch (727:69): [True: 0, False: 0]
  ------------------
  728|      0|                _zip_cdir_free(cdir);
  729|      0|                cdir = NULL;
  730|      0|            }
  731|  3.24k|            break;
  732|  3.24k|        }
  733|  25.9k|    }
  734|       |
  735|  3.67k|    _zip_buffer_free(buffer);
  736|       |
  737|  3.67k|    if (cdir == NULL) {
  ------------------
  |  Branch (737:9): [True: 2.47k, False: 1.20k]
  ------------------
  738|  2.47k|        _zip_error_copy(&za->error, &error);
  739|  2.47k|    }
  740|  3.67k|    return cdir;
  741|  3.67k|}
zip_open.c:find_eocd:
  744|  26.3k|static const unsigned char *find_eocd(zip_buffer_t *buffer, const unsigned char *last) {
  745|  26.3k|    const unsigned char *data = _zip_buffer_data(buffer);
  746|  26.3k|    const unsigned char *p;
  747|       |
  748|  26.3k|    if (last == NULL) {
  ------------------
  |  Branch (748:9): [True: 3.67k, False: 22.6k]
  ------------------
  749|  3.67k|        if (_zip_buffer_size(buffer) < MAGIC_LEN) {
  ------------------
  |  |   57|  3.67k|#define MAGIC_LEN 4
  ------------------
  |  Branch (749:13): [True: 0, False: 3.67k]
  ------------------
  750|      0|            return NULL;
  751|      0|        }
  752|  3.67k|        last = data + _zip_buffer_size(buffer) - MAGIC_LEN;
  ------------------
  |  |   57|  3.67k|#define MAGIC_LEN 4
  ------------------
  753|  3.67k|    }
  754|  22.6k|    else {
  755|  22.6k|        if (last == _zip_buffer_data(buffer)) {
  ------------------
  |  Branch (755:13): [True: 210, False: 22.4k]
  ------------------
  756|    210|            return NULL;
  757|    210|        }
  758|  22.4k|        last -= 1;
  759|  22.4k|    }
  760|       |
  761|  4.87M|    for (p = last; p >= data; p -= 1) {
  ------------------
  |  Branch (761:20): [True: 4.87M, False: 0]
  ------------------
  762|  4.87M|        if (*p == EOCD_MAGIC[0]) {
  ------------------
  |  |   53|  4.87M|#define EOCD_MAGIC "PK\5\6"
  ------------------
  |  Branch (762:13): [True: 76.3k, False: 4.79M]
  ------------------
  763|  76.3k|            if (memcmp(p, EOCD_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   53|  76.3k|#define EOCD_MAGIC "PK\5\6"
  ------------------
                          if (memcmp(p, EOCD_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   57|  76.3k|#define MAGIC_LEN 4
  ------------------
  |  Branch (763:17): [True: 25.9k, False: 50.4k]
  ------------------
  764|  25.9k|                return p;
  765|  25.9k|            }
  766|  76.3k|        }
  767|  4.85M|        if (p == data) {
  ------------------
  |  Branch (767:13): [True: 218, False: 4.85M]
  ------------------
  768|       |            /* Avoid undefined behavior by creating pointer outside buffer */
  769|    218|            break;
  770|    218|        }
  771|  4.85M|    }
  772|       |
  773|    218|    return NULL;
  774|  26.1k|}
zip_open.c:_zip_read_cdir:
  288|  25.9k|static bool _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_cdir_t **cdirp, zip_error_t *error) {
  289|  25.9k|    zip_cdir_t *cd;
  290|  25.9k|    zip_uint16_t comment_len;
  291|  25.9k|    zip_uint64_t i, left;
  292|  25.9k|    zip_uint64_t eocd_offset = _zip_buffer_offset(buffer);
  293|  25.9k|    zip_buffer_t *cd_buffer;
  294|  25.9k|    bool eocd64_found = false;
  295|       |
  296|  25.9k|    *cdirp = NULL;
  297|       |
  298|  25.9k|    if ((cd = _zip_read_eocd(buffer, buf_offset, error)) == NULL) {
  ------------------
  |  Branch (298:9): [True: 198, False: 25.7k]
  ------------------
  299|    198|        return false;
  300|    198|    }
  301|       |
  302|  25.7k|    if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
  ------------------
  |  |   63|  51.4k|#define EOCD64LOCLEN 20
  ------------------
                  if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
  ------------------
  |  |   63|  24.7k|#define EOCD64LOCLEN 20
  ------------------
                  if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
  ------------------
  |  |   55|  24.7k|#define EOCD64LOC_MAGIC "PK\6\7"
  ------------------
  |  Branch (302:9): [True: 24.7k, False: 1.02k]
  |  Branch (302:40): [True: 2.95k, False: 21.7k]
  ------------------
  303|  2.95k|        eocd64_found = true;
  304|  2.95k|        _zip_buffer_set_offset(buffer, eocd_offset - EOCD64LOCLEN);
  ------------------
  |  |   63|  2.95k|#define EOCD64LOCLEN 20
  ------------------
  305|  2.95k|        switch (_zip_read_eocd64(cd, za->src, buffer, buf_offset, za->open_flags, error)) {
  ------------------
  |  Branch (305:17): [True: 2.95k, False: 0]
  ------------------
  306|    176|        case CDIR_OK:
  ------------------
  |  Branch (306:9): [True: 176, False: 2.77k]
  ------------------
  307|    176|            break;
  308|       |
  309|    758|        case CDIR_INVALID:
  ------------------
  |  Branch (309:9): [True: 758, False: 2.19k]
  ------------------
  310|    758|            _zip_cdir_free(cd);
  311|    758|            return true;
  312|       |
  313|  2.01k|        case CDIR_NOT_FOUND:
  ------------------
  |  Branch (313:9): [True: 2.01k, False: 934]
  ------------------
  314|  2.01k|            _zip_cdir_free(cd);
  315|  2.01k|            return false;
  316|  2.95k|        }
  317|  2.95k|    }
  318|       |
  319|  22.9k|    if ((cd->eocd_disk != 0 || cd->this_disk != 0) && !eocd64_found && cd->eocd_disk != cd->this_disk) {
  ------------------
  |  Branch (319:10): [True: 12.0k, False: 10.9k]
  |  Branch (319:32): [True: 3.80k, False: 7.13k]
  |  Branch (319:55): [True: 15.7k, False: 64]
  |  Branch (319:72): [True: 14.2k, False: 1.49k]
  ------------------
  320|       |        /* If the central directory doesn't start on this disk, we can't check that offset is valid. Check as much as we can instead. */
  321|  14.2k|        if (cd->this_disk < cd->eocd_disk) {
  ------------------
  |  Branch (321:13): [True: 2.01k, False: 12.2k]
  ------------------
  322|       |            /* Disks before the start of the central directory don't contain an EOCD. */
  323|  2.01k|            _zip_cdir_free(cd);
  324|  2.01k|            return false;
  325|  2.01k|        }
  326|  12.2k|        if (cd->size <= cd->eocd_offset) {
  ------------------
  |  Branch (326:13): [True: 2.11k, False: 10.1k]
  ------------------
  327|       |            /* The complete central directory would fit on this disk. */
  328|  2.11k|            _zip_cdir_free(cd);
  329|  2.11k|            return false;
  330|  2.11k|        }
  331|  12.2k|    }
  332|       |
  333|  18.8k|    if (!eocd64_found) {
  ------------------
  |  Branch (333:9): [True: 18.6k, False: 176]
  ------------------
  334|  18.6k|        if (cd->this_disk == 0 && cd->eocd_disk == 0 && cd->eocd_offset == 0 && cd->offset == 0 && cd->num_entries == 0) {
  ------------------
  |  Branch (334:13): [True: 7.02k, False: 11.6k]
  |  Branch (334:35): [True: 7.02k, False: 0]
  |  Branch (334:57): [True: 574, False: 6.45k]
  |  Branch (334:81): [True: 523, False: 51]
  |  Branch (334:100): [True: 505, False: 18]
  ------------------
  335|       |            /* An empty archive doesn't contain central directory entries. */
  336|    505|        }
  337|  18.1k|        else if (!check_magic(cd->offset, buffer, buf_offset, za->src, CENTRAL_MAGIC)) {
  ------------------
  |  |   51|  18.1k|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (337:18): [True: 16.3k, False: 1.80k]
  ------------------
  338|  16.3k|            _zip_cdir_free(cd);
  339|  16.3k|            return false;
  340|  16.3k|        }
  341|  18.6k|    }
  342|       |
  343|       |    /* We accept this EOCD as valid and won't search for an earlier one if it is unusable. */
  344|       |
  345|  2.48k|    if (!check_eocd(cd, za->flags, error)) {
  ------------------
  |  Branch (345:9): [True: 106, False: 2.38k]
  ------------------
  346|    106|        _zip_cdir_free(cd);
  347|    106|        return true;
  348|    106|    }
  349|       |
  350|  2.38k|    _zip_buffer_set_offset(buffer, eocd_offset + 20);
  351|  2.38k|    comment_len = _zip_buffer_get_16(buffer);
  352|       |
  353|  2.38k|    if (cd->offset + cd->size > buf_offset + eocd_offset) {
  ------------------
  |  Branch (353:9): [True: 127, False: 2.25k]
  ------------------
  354|       |        /* cdir spans past EOCD record */
  355|    127|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD);
  ------------------
  |  |  152|    127|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD);
  ------------------
  |  |  222|    127|#define ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD 1                /* G central directory overlaps EOCD, or there is space between them */
  ------------------
  356|    127|        _zip_cdir_free(cd);
  357|    127|        return true;
  358|    127|    }
  359|       |
  360|  2.25k|    if (comment_len || (za->open_flags & ZIP_CHECKCONS)) {
  ------------------
  |  |   88|    279|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (360:9): [True: 1.97k, False: 279]
  |  Branch (360:24): [True: 0, False: 279]
  ------------------
  361|  1.97k|        zip_uint64_t tail_len;
  362|       |
  363|  1.97k|        _zip_buffer_set_offset(buffer, eocd_offset + EOCDLEN);
  ------------------
  |  |   62|  1.97k|#define EOCDLEN 22
  ------------------
  364|  1.97k|        tail_len = _zip_buffer_left(buffer);
  365|       |
  366|  1.97k|        if (tail_len != comment_len) {
  ------------------
  |  Branch (366:13): [True: 1.90k, False: 76]
  ------------------
  367|  1.90k|            if (za->open_flags & ZIP_CHECKCONS) {
  ------------------
  |  |   88|  1.90k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (367:17): [True: 0, False: 1.90k]
  ------------------
  368|      0|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID);
  ------------------
  |  |  223|      0|#define ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID 2            /* G archive comment length incorrect */
  ------------------
  369|      0|                _zip_cdir_free(cd);
  370|      0|                return true;
  371|      0|            }
  372|  1.90k|            if (tail_len < comment_len) {
  ------------------
  |  Branch (372:17): [True: 1.80k, False: 93]
  ------------------
  373|  1.80k|                comment_len = tail_len;
  374|  1.80k|            }
  375|  1.90k|        }
  376|       |
  377|  1.97k|        if (comment_len) {
  ------------------
  |  Branch (377:13): [True: 815, False: 1.16k]
  ------------------
  378|    815|            if ((cd->comment = _zip_string_new(_zip_buffer_get(buffer, comment_len), comment_len, ZIP_FL_ENC_GUESS, error)) == NULL) {
  ------------------
  |  |  101|    815|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (378:17): [True: 0, False: 815]
  ------------------
  379|      0|                _zip_cdir_free(cd);
  380|      0|                return true;
  381|      0|            }
  382|    815|        }
  383|  1.97k|    }
  384|       |
  385|  2.25k|    if (cd->offset >= buf_offset) {
  ------------------
  |  Branch (385:9): [True: 2.09k, False: 165]
  ------------------
  386|  2.09k|        zip_uint8_t *data;
  387|       |        /* if buffer already read in, use it */
  388|  2.09k|        _zip_buffer_set_offset(buffer, cd->offset - buf_offset);
  389|       |
  390|  2.09k|        if ((data = _zip_buffer_get(buffer, cd->size)) == NULL) {
  ------------------
  |  Branch (390:13): [True: 0, False: 2.09k]
  ------------------
  391|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  224|      0|#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID 3               /* G central directory length invalid */
  ------------------
  392|      0|            _zip_cdir_free(cd);
  393|      0|            return true;
  394|      0|        }
  395|  2.09k|        if ((cd_buffer = _zip_buffer_new(data, cd->size)) == NULL) {
  ------------------
  |  Branch (395:13): [True: 0, False: 2.09k]
  ------------------
  396|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  397|      0|            _zip_cdir_free(cd);
  398|      0|            return true;
  399|      0|        }
  400|  2.09k|    }
  401|    165|    else {
  402|    165|        cd_buffer = NULL;
  403|       |
  404|    165|        if (zip_source_seek(za->src, (zip_int64_t)cd->offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (404:13): [True: 0, False: 165]
  ------------------
  405|      0|            zip_error_set_from_source(error, za->src);
  406|      0|            _zip_cdir_free(cd);
  407|      0|            return true;
  408|      0|        }
  409|       |
  410|       |        /* possible consistency check: cd->offset = len-(cd->size+cd->comment_len+EOCDLEN) ? */
  411|    165|        if (zip_source_tell(za->src) != (zip_int64_t)cd->offset) {
  ------------------
  |  Branch (411:13): [True: 0, False: 165]
  ------------------
  412|      0|            zip_error_set(error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|      0|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  413|      0|            _zip_cdir_free(cd);
  414|      0|            return true;
  415|      0|        }
  416|    165|    }
  417|       |
  418|  2.25k|    if (!_zip_cdir_grow(cd, cd->num_entries, error)) {
  ------------------
  |  Branch (418:9): [True: 0, False: 2.25k]
  ------------------
  419|      0|        _zip_cdir_free(cd);
  420|      0|        _zip_buffer_free(cd_buffer);
  421|      0|        return true;
  422|      0|    }
  423|  2.25k|    left = (zip_uint64_t)cd->size;
  424|  2.25k|    i = 0;
  425|  74.6k|    while (left > 0) {
  ------------------
  |  Branch (425:12): [True: 73.3k, False: 1.30k]
  ------------------
  426|  73.3k|        bool grown = false;
  427|  73.3k|        zip_int64_t entry_size;
  428|       |
  429|  73.3k|        if (i == cd->nentry) {
  ------------------
  |  Branch (429:13): [True: 462, False: 72.9k]
  ------------------
  430|       |            /* InfoZIP has a hack to avoid using Zip64: it stores nentries % 0x10000 */
  431|       |            /* This hack isn't applicable if we're using Zip64, or if there is no central directory entry following. */
  432|       |
  433|    462|            if (cd->is_zip64 || left < CDENTRYSIZE) {
  ------------------
  |  |   58|    454|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (433:17): [True: 8, False: 454]
  |  Branch (433:33): [True: 27, False: 427]
  ------------------
  434|     35|                break;
  435|     35|            }
  436|       |
  437|    427|            if (!_zip_cdir_grow(cd, 0x10000, error)) {
  ------------------
  |  Branch (437:17): [True: 0, False: 427]
  ------------------
  438|      0|                _zip_cdir_free(cd);
  439|      0|                _zip_buffer_free(cd_buffer);
  440|      0|                return true;
  441|      0|            }
  442|    427|            grown = true;
  443|    427|        }
  444|       |
  445|  73.3k|        if ((cd->entry[i].orig = _zip_dirent_new()) == NULL || (entry_size = _zip_dirent_read(cd->entry[i].orig, za->src, cd_buffer, false, cd->is_zip64, 0, za->open_flags & ZIP_CHECKCONS, error)) < 0) {
  ------------------
  |  |   88|  73.3k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (445:13): [True: 0, False: 73.3k]
  |  Branch (445:64): [True: 917, False: 72.4k]
  ------------------
  446|    917|            if (zip_error_code_zip(error) == ZIP_ER_INCONS) {
  ------------------
  |  |  152|    917|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
  |  Branch (446:17): [True: 556, False: 361]
  ------------------
  447|    556|                zip_error_set(error, ZIP_ER_INCONS, ADD_INDEX_TO_DETAIL(zip_error_code_system(error), i));
  ------------------
  |  |  152|    556|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ADD_INDEX_TO_DETAIL(zip_error_code_system(error), i));
  ------------------
  |  |  218|    556|#define ADD_INDEX_TO_DETAIL(error, index) MAKE_DETAIL_WITH_INDEX(GET_ERROR_FROM_DETAIL(error), (index))
  |  |  ------------------
  |  |  |  |  215|    556|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  |  |  ------------------
  |  |  |  |  |  |  214|    556|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  |  |  ------------------
  |  |  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  |  |  ------------------
  |  |  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (215:48): [True: 0, False: 556]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  448|    556|            }
  449|    361|            else if (grown && zip_error_code_zip(error) == ZIP_ER_NOZIP) {
  ------------------
  |  |  150|    120|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  |  Branch (449:22): [True: 120, False: 241]
  |  Branch (449:31): [True: 37, False: 83]
  ------------------
  450|     37|                zip_error_set(error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, i));
  ------------------
  |  |  152|     37|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, i));
  ------------------
  |  |  215|     37|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|     37|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |  |  Branch (215:48): [True: 0, False: 37]
  |  |  ------------------
  ------------------
  451|     37|            }
  452|    917|            _zip_cdir_free(cd);
  453|    917|            _zip_buffer_free(cd_buffer);
  454|    917|            return true;
  455|    917|        }
  456|  72.4k|        i++;
  457|  72.4k|        left -= (zip_uint64_t)entry_size;
  458|  72.4k|    }
  459|       |
  460|       |    /* If we didn't fill all we grew, cd->num_entries was wrong. */
  461|  1.33k|    if (i != cd->nentry || left > 0) {
  ------------------
  |  Branch (461:9): [True: 101, False: 1.23k]
  |  Branch (461:28): [True: 35, False: 1.20k]
  ------------------
  462|    136|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT);
  ------------------
  |  |  152|    136|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT);
  ------------------
  |  |  226|    136|#define ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT 5          /* G central directory count of entries is incorrect */
  ------------------
  463|    136|        _zip_buffer_free(cd_buffer);
  464|    136|        _zip_cdir_free(cd);
  465|    136|        return true;
  466|    136|    }
  467|       |
  468|  1.20k|    if (za->open_flags & ZIP_CHECKCONS) {
  ------------------
  |  |   88|  1.20k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (468:9): [True: 0, False: 1.20k]
  ------------------
  469|      0|        bool ok;
  470|       |
  471|      0|        if (cd_buffer) {
  ------------------
  |  Branch (471:13): [True: 0, False: 0]
  ------------------
  472|      0|            ok = _zip_buffer_eof(cd_buffer);
  473|      0|        }
  474|      0|        else {
  475|      0|            zip_int64_t offset = zip_source_tell(za->src);
  476|       |
  477|      0|            if (offset < 0) {
  ------------------
  |  Branch (477:17): [True: 0, False: 0]
  ------------------
  478|      0|                zip_error_set_from_source(error, za->src);
  479|      0|                _zip_cdir_free(cd);
  480|      0|                return true;
  481|      0|            }
  482|      0|            ok = ((zip_uint64_t)offset == cd->offset + cd->size);
  483|      0|        }
  484|       |
  485|      0|        if (!ok) {
  ------------------
  |  Branch (485:13): [True: 0, False: 0]
  ------------------
  486|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  224|      0|#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID 3               /* G central directory length invalid */
  ------------------
  487|      0|            _zip_buffer_free(cd_buffer);
  488|      0|            _zip_cdir_free(cd);
  489|      0|            return true;
  490|      0|        }
  491|      0|    }
  492|       |
  493|  1.20k|    _zip_buffer_free(cd_buffer);
  494|  1.20k|    *cdirp = cd;
  495|       |    return true;
  496|  1.20k|}
zip_open.c:_zip_read_eocd:
  777|  25.9k|static zip_cdir_t *_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error) {
  778|  25.9k|    zip_cdir_t *cd;
  779|       |
  780|  25.9k|    if (_zip_buffer_left(buffer) < EOCDLEN) {
  ------------------
  |  |   62|  25.9k|#define EOCDLEN 22
  ------------------
  |  Branch (780:9): [True: 198, False: 25.7k]
  ------------------
  781|    198|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD_LENGTH_INVALID);
  ------------------
  |  |  152|    198|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD_LENGTH_INVALID);
  ------------------
  |  |  228|    198|#define ZIP_ER_DETAIL_EOCD_LENGTH_INVALID 7               /* G wrong EOCD length */
  ------------------
  782|    198|        return NULL;
  783|    198|    }
  784|       |
  785|  25.7k|    if ((cd = _zip_cdir_new(error)) == NULL) {
  ------------------
  |  Branch (785:9): [True: 0, False: 25.7k]
  ------------------
  786|      0|        return NULL;
  787|      0|    }
  788|       |
  789|  25.7k|    cd->eocd_offset = buf_offset + _zip_buffer_offset(buffer);
  790|       |    /* This function is only called where EOCD magic was found, so no need to check that here. */
  791|  25.7k|    _zip_buffer_skip(buffer, MAGIC_LEN);
  ------------------
  |  |   57|  25.7k|#define MAGIC_LEN 4
  ------------------
  792|  25.7k|    cd->is_zip64 = false;
  793|  25.7k|    cd->this_disk = _zip_buffer_get_16(buffer);
  794|  25.7k|    cd->eocd_disk = _zip_buffer_get_16(buffer);
  795|       |
  796|       |    /* number of cdir-entries on this disk */
  797|  25.7k|    cd->disk_entries = _zip_buffer_get_16(buffer);
  798|       |    /* number of cdir-entries */
  799|  25.7k|    cd->num_entries = _zip_buffer_get_16(buffer);
  800|  25.7k|    cd->size = _zip_buffer_get_32(buffer);
  801|  25.7k|    cd->offset = _zip_buffer_get_32(buffer);
  802|       |
  803|  25.7k|    return cd;
  804|  25.7k|}
zip_open.c:_zip_read_eocd64:
  825|  2.95k|cdir_status_t _zip_read_eocd64(zip_cdir_t *cdir, zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error) {
  826|  2.95k|    zip_uint64_t offset;
  827|  2.95k|    zip_uint8_t eocd[EOCD64LEN];
  828|  2.95k|    zip_uint64_t eocd_offset;
  829|  2.95k|    zip_uint64_t size, nentry, i, eocdloc_offset;
  830|  2.95k|    bool free_buffer;
  831|  2.95k|    zip_uint32_t num_disks, eocd_disk, this_disk;
  832|       |
  833|       |    /* The offset of the end of the buffer is less than ZIP_UINT64_MAX, so this can't overflow. */
  834|  2.95k|    eocdloc_offset = buf_offset + _zip_buffer_offset(buffer);
  835|       |
  836|  2.95k|    _zip_buffer_get(buffer, 4); /* magic already verified */
  837|       |
  838|  2.95k|    eocd_disk = _zip_buffer_get_32(buffer);
  839|  2.95k|    eocd_offset = _zip_buffer_get_64(buffer);
  840|  2.95k|    num_disks = _zip_buffer_get_32(buffer);
  841|       |
  842|  2.95k|    if (!check_magic(eocd_offset, buffer, buf_offset, src, EOCD64_MAGIC)) {
  ------------------
  |  |   56|  2.95k|#define EOCD64_MAGIC "PK\6\6"
  ------------------
  |  Branch (842:9): [True: 2.01k, False: 934]
  ------------------
  843|  2.01k|        return CDIR_NOT_FOUND;
  844|  2.01k|    }
  845|       |
  846|    934|    if (num_disks != 1) {
  ------------------
  |  Branch (846:9): [True: 42, False: 892]
  ------------------
  847|     42|        zip_error_set(error, ZIP_ER_MULTIDISK, 0);
  ------------------
  |  |  132|     42|#define ZIP_ER_MULTIDISK 1        /* N Multi-disk zip archives not supported */
  ------------------
  848|     42|        return CDIR_INVALID;
  849|     42|    }
  850|       |
  851|       |    /* valid seek value for start of EOCD */
  852|    892|    if (eocd_offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|    892|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (852:9): [True: 0, False: 892]
  ------------------
  853|      0|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  854|      0|        return CDIR_INVALID;
  855|      0|    }
  856|       |
  857|       |    /* does EOCD fit before EOCD locator? */
  858|    892|    if (eocd_offset + EOCD64LEN > eocdloc_offset) {
  ------------------
  |  |   64|    892|#define EOCD64LEN 56
  ------------------
  |  Branch (858:9): [True: 30, False: 862]
  ------------------
  859|     30|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  152|     30|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  229|     30|#define ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD 8              /* G EOCD64 overlaps EOCD, or there is space between them */
  ------------------
  860|     30|        return CDIR_INVALID;
  861|     30|    }
  862|       |
  863|       |    /* make sure current position of buffer is beginning of EOCD */
  864|    862|    if (eocd_offset >= buf_offset && eocd_offset + EOCD64LEN <= buf_offset + _zip_buffer_size(buffer)) {
  ------------------
  |  |   64|    835|#define EOCD64LEN 56
  ------------------
  |  Branch (864:9): [True: 835, False: 27]
  |  Branch (864:38): [True: 835, False: 0]
  ------------------
  865|    835|        _zip_buffer_set_offset(buffer, eocd_offset - buf_offset);
  866|    835|        free_buffer = false;
  867|    835|    }
  868|     27|    else {
  869|     27|        if (zip_source_seek(src, (zip_int64_t)eocd_offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (869:13): [True: 0, False: 27]
  ------------------
  870|      0|            zip_error_set_from_source(error, src);
  871|      0|            return CDIR_INVALID;
  872|      0|        }
  873|     27|        if ((buffer = _zip_buffer_new_from_source(src, EOCD64LEN, eocd, error)) == NULL) {
  ------------------
  |  |   64|     27|#define EOCD64LEN 56
  ------------------
  |  Branch (873:13): [True: 0, False: 27]
  ------------------
  874|      0|            return CDIR_INVALID;
  875|      0|        }
  876|     27|        free_buffer = true;
  877|     27|    }
  878|       |
  879|    862|    if (memcmp(_zip_buffer_get(buffer, 4), EOCD64_MAGIC, 4) != 0) {
  ------------------
  |  |   56|    862|#define EOCD64_MAGIC "PK\6\6"
  ------------------
  |  Branch (879:9): [True: 0, False: 862]
  ------------------
  880|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC);
  ------------------
  |  |  230|      0|#define ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC 9                /* G EOCD64 magic incorrect */
  ------------------
  881|      0|        if (free_buffer) {
  ------------------
  |  Branch (881:13): [True: 0, False: 0]
  ------------------
  882|      0|            _zip_buffer_free(buffer);
  883|      0|        }
  884|      0|        return CDIR_INVALID;
  885|      0|    }
  886|       |
  887|       |    /* size of EOCD */
  888|    862|    size = _zip_buffer_get_64(buffer);
  889|       |
  890|       |    /* Is there a hole between EOCD and EOCD locator, or do they overlap? Also check for overflow. */
  891|    862|    if ((flags & ZIP_CHECKCONS) && (ZIP_CHECK_ADD_OVERFLOW(size, eocd_offset + 12) || size + eocd_offset + 12 != eocdloc_offset)) {
  ------------------
  |  |   88|    862|#define ZIP_CHECKCONS 4
  ------------------
                  if ((flags & ZIP_CHECKCONS) && (ZIP_CHECK_ADD_OVERFLOW(size, eocd_offset + 12) || size + eocd_offset + 12 != eocdloc_offset)) {
  ------------------
  |  |  511|      0|#define ZIP_CHECK_ADD_OVERFLOW(a, b) ((a) + (b) < (a))
  |  |  ------------------
  |  |  |  Branch (511:38): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (891:9): [True: 0, False: 862]
  |  Branch (891:87): [True: 0, False: 0]
  ------------------
  892|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  229|      0|#define ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD 8              /* G EOCD64 overlaps EOCD, or there is space between them */
  ------------------
  893|      0|        if (free_buffer) {
  ------------------
  |  Branch (893:13): [True: 0, False: 0]
  ------------------
  894|      0|            _zip_buffer_free(buffer);
  895|      0|        }
  896|      0|        return CDIR_INVALID;
  897|      0|    }
  898|       |
  899|    862|    _zip_buffer_get(buffer, 4); /* skip version made by/needed */
  900|       |
  901|    862|    this_disk = _zip_buffer_get_32(buffer);
  902|    862|    if (_zip_buffer_get_32(buffer) != eocd_disk) {
  ------------------
  |  Branch (902:9): [True: 60, False: 802]
  ------------------
  903|     60|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_LOCATOR_MISMATCH);
  ------------------
  |  |  152|     60|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_LOCATOR_MISMATCH);
  ------------------
  |  |  243|     60|#define ZIP_ER_DETAIL_EOCD64_LOCATOR_MISMATCH 22          /* G EOCD64 and EOCD64 locator do not match */
  ------------------
  904|     60|        if (free_buffer) {
  ------------------
  |  Branch (904:13): [True: 12, False: 48]
  ------------------
  905|     12|            _zip_buffer_free(buffer);
  906|     12|        }
  907|     60|        return CDIR_INVALID;
  908|     60|    }
  909|       |
  910|    802|    i = _zip_buffer_get_64(buffer);
  911|    802|    nentry = _zip_buffer_get_64(buffer);
  912|       |
  913|    802|    if (nentry != i) {
  ------------------
  |  Branch (913:9): [True: 108, False: 694]
  ------------------
  914|    108|        zip_error_set(error, ZIP_ER_MULTIDISK, 0);
  ------------------
  |  |  132|    108|#define ZIP_ER_MULTIDISK 1        /* N Multi-disk zip archives not supported */
  ------------------
  915|    108|        if (free_buffer) {
  ------------------
  |  Branch (915:13): [True: 4, False: 104]
  ------------------
  916|      4|            _zip_buffer_free(buffer);
  917|      4|        }
  918|    108|        return CDIR_INVALID;
  919|    108|    }
  920|       |
  921|    694|    size = _zip_buffer_get_64(buffer);
  922|    694|    offset = _zip_buffer_get_64(buffer);
  923|       |
  924|       |    /* did we read past the end of the buffer? */
  925|    694|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (925:9): [True: 0, False: 694]
  ------------------
  926|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  927|      0|        if (free_buffer) {
  ------------------
  |  Branch (927:13): [True: 0, False: 0]
  ------------------
  928|      0|            _zip_buffer_free(buffer);
  929|      0|        }
  930|      0|        return CDIR_INVALID;
  931|      0|    }
  932|       |
  933|    694|    if (free_buffer) {
  ------------------
  |  Branch (933:9): [True: 11, False: 683]
  ------------------
  934|     11|        _zip_buffer_free(buffer);
  935|     11|    }
  936|       |
  937|    694|    if (offset > ZIP_INT64_MAX || offset + size < offset) {
  ------------------
  |  |   45|  1.38k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (937:9): [True: 62, False: 632]
  |  Branch (937:35): [True: 2, False: 630]
  ------------------
  938|     64|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|     64|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  939|     64|        return CDIR_INVALID;
  940|     64|    }
  941|       |
  942|    630|    if (nentry > size / CDENTRYSIZE) {
  ------------------
  |  |   58|    630|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (942:9): [True: 44, False: 586]
  ------------------
  943|     44|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_INVALID);
  ------------------
  |  |  152|     44|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_INVALID);
  ------------------
  |  |  232|     44|#define ZIP_ER_DETAIL_CDIR_INVALID 11                     /* G invalid value in central directory */
  ------------------
  944|     44|        return CDIR_INVALID;
  945|     44|    }
  946|       |
  947|    586|    if ((cdir->size != 0xffffffff && cdir->size != size) || (cdir->offset != 0xffffffff && cdir->offset != offset) || (cdir->num_entries != 0xffff && cdir->num_entries != nentry) || (cdir->disk_entries != 0xffff && cdir->disk_entries != i) || (cdir->this_disk != 0xffff && cdir->this_disk != this_disk) || (cdir->eocd_disk != 0xffff && cdir->eocd_disk != eocd_disk)) {
  ------------------
  |  Branch (947:10): [True: 131, False: 455]
  |  Branch (947:38): [True: 105, False: 26]
  |  Branch (947:62): [True: 98, False: 383]
  |  Branch (947:92): [True: 85, False: 13]
  |  Branch (947:120): [True: 86, False: 310]
  |  Branch (947:151): [True: 61, False: 25]
  |  Branch (947:184): [True: 86, False: 249]
  |  Branch (947:216): [True: 62, False: 24]
  |  Branch (947:245): [True: 97, False: 176]
  |  Branch (947:274): [True: 52, False: 45]
  |  Branch (947:308): [True: 57, False: 164]
  |  Branch (947:337): [True: 45, False: 12]
  ------------------
  948|    410|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_MISMATCH);
  ------------------
  |  |  152|    410|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_MISMATCH);
  ------------------
  |  |  231|    410|#define ZIP_ER_DETAIL_EOCD64_MISMATCH 10                  /* G EOCD64 and EOCD do not match */
  ------------------
  949|    410|        return CDIR_INVALID;
  950|    410|    }
  951|       |
  952|    176|    cdir->is_zip64 = true;
  953|    176|    cdir->size = size;
  954|    176|    cdir->offset = offset;
  955|    176|    cdir->disk_entries = i;
  956|    176|    cdir->num_entries = nentry;
  957|    176|    cdir->this_disk = this_disk;
  958|    176|    cdir->eocd_disk = eocd_disk;
  959|       |
  960|    176|    return CDIR_OK;
  961|    586|}
zip_open.c:check_magic:
  499|  21.0k|static bool check_magic(zip_uint64_t offset, zip_buffer_t *buffer, zip_uint64_t buffer_offset, zip_source_t *src, const char *magic) {
  500|  21.0k|    if (buffer_offset <= offset) {
  ------------------
  |  Branch (500:9): [True: 19.4k, False: 1.61k]
  ------------------
  501|  19.4k|        zip_uint8_t *data;
  502|  19.4k|        if (_zip_buffer_set_offset(buffer, offset - buffer_offset) < 0 || (data = _zip_buffer_get(buffer, MAGIC_LEN)) == NULL) {
  ------------------
  |  |   57|  6.87k|#define MAGIC_LEN 4
  ------------------
  |  Branch (502:13): [True: 12.6k, False: 6.87k]
  |  Branch (502:75): [True: 349, False: 6.52k]
  ------------------
  503|  12.9k|            return false;
  504|  12.9k|        }
  505|  6.52k|        return memcmp(data, magic, MAGIC_LEN) == 0;
  ------------------
  |  |   57|  6.52k|#define MAGIC_LEN 4
  ------------------
  506|  19.4k|    }
  507|  1.61k|    else {
  508|  1.61k|        zip_uint8_t data[MAGIC_LEN];
  509|       |
  510|  1.61k|        if (zip_source_seek(src, offset, SEEK_SET) < 0 || zip_source_read(src, data, MAGIC_LEN) != MAGIC_LEN) {
  ------------------
  |  |   57|  1.61k|#define MAGIC_LEN 4
  ------------------
                      if (zip_source_seek(src, offset, SEEK_SET) < 0 || zip_source_read(src, data, MAGIC_LEN) != MAGIC_LEN) {
  ------------------
  |  |   57|  1.61k|#define MAGIC_LEN 4
  ------------------
  |  Branch (510:13): [True: 0, False: 1.61k]
  |  Branch (510:59): [True: 0, False: 1.61k]
  ------------------
  511|      0|            return false;
  512|      0|        }
  513|  1.61k|        return memcmp(data, magic, MAGIC_LEN) == 0;
  ------------------
  |  |   57|  1.61k|#define MAGIC_LEN 4
  ------------------
  514|  1.61k|    }
  515|  21.0k|}
zip_open.c:check_eocd:
  806|  2.48k|static bool check_eocd(zip_cdir_t *cd, unsigned int flags, zip_error_t *error) {
  807|  2.48k|    if (cd->disk_entries != cd->num_entries || cd->this_disk != 0 || cd->eocd_disk != 0) {
  ------------------
  |  Branch (807:9): [True: 26, False: 2.46k]
  |  Branch (807:48): [True: 48, False: 2.41k]
  |  Branch (807:70): [True: 32, False: 2.38k]
  ------------------
  808|    106|        zip_error_set(error, ZIP_ER_MULTIDISK, 0);
  ------------------
  |  |  132|    106|#define ZIP_ER_MULTIDISK 1        /* N Multi-disk zip archives not supported */
  ------------------
  809|    106|        return false;
  810|    106|    }
  811|       |
  812|  2.38k|    if (cd->offset + cd->size < cd->offset) {
  ------------------
  |  Branch (812:9): [True: 0, False: 2.38k]
  ------------------
  813|      0|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  814|      0|        return false;
  815|      0|    }
  816|  2.38k|    if ((flags & ZIP_CHECKCONS) && cd->offset + cd->size != cd->eocd_offset) {
  ------------------
  |  |   88|  2.38k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (816:9): [True: 0, False: 2.38k]
  |  Branch (816:36): [True: 0, False: 0]
  ------------------
  817|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  224|      0|#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID 3               /* G central directory length invalid */
  ------------------
  818|      0|        return false;
  819|      0|    }
  820|       |
  821|  2.38k|    return true;
  822|  2.38k|}
zip_open.c:zip_check_torrentzip:
  979|  1.20k|static void zip_check_torrentzip(zip_t *za, const zip_cdir_t *cdir) {
  980|  1.20k|    zip_uint32_t crc_should;
  981|  1.20k|    char buf[8 + 1];
  982|  1.20k|    size_t i;
  983|       |
  984|  1.20k|    if (cdir == NULL) {
  ------------------
  |  Branch (984:9): [True: 0, False: 1.20k]
  ------------------
  985|      0|        return;
  986|      0|    }
  987|       |
  988|  1.20k|    if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   72|  1.20k|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
                  if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   73|  2.40k|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
                  if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   71|    240|#define TORRENTZIP_SIGNATURE "TORRENTZIPPED-"
  ------------------
                  if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   72|    240|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
  |  Branch (988:9): [True: 963, False: 240]
  |  Branch (988:101): [True: 124, False: 116]
  ------------------
  989|  1.08k|        return;
  990|  1.08k|    }
  991|       |
  992|    116|    memcpy(buf, cdir->comment->raw + TORRENTZIP_SIGNATURE_LENGTH, TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   72|    116|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
                  memcpy(buf, cdir->comment->raw + TORRENTZIP_SIGNATURE_LENGTH, TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   73|    116|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  993|    116|    buf[TORRENTZIP_CRC_LENGTH] = '\0';
  ------------------
  |  |   73|    116|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  994|    116|    crc_should = 0;
  995|    488|    for (i = 0; i < TORRENTZIP_CRC_LENGTH; i += 2) {
  ------------------
  |  |   73|    488|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  |  Branch (995:17): [True: 404, False: 84]
  ------------------
  996|    404|        int low, high;
  997|    404|        high = decode_hex((buf[i]));
  998|    404|        low = decode_hex(buf[i + 1]);
  999|    404|        if (high < 0 || low < 0) {
  ------------------
  |  Branch (999:13): [True: 21, False: 383]
  |  Branch (999:25): [True: 11, False: 372]
  ------------------
 1000|     32|            return;
 1001|     32|        }
 1002|    372|        crc_should = (crc_should << 8) + (high << 4) + low;
 1003|    372|    }
 1004|       |
 1005|     84|    {
 1006|     84|        zip_stat_t st;
 1007|     84|        zip_source_t *src_window;
 1008|     84|        zip_source_t *src_crc;
 1009|     84|        zip_uint8_t buffer[512];
 1010|     84|        zip_int64_t ret;
 1011|       |
 1012|     84|        zip_stat_init(&st);
 1013|     84|        st.valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC;
  ------------------
  |  |  325|     84|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      st.valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC;
  ------------------
  |  |  328|     84|#define ZIP_STAT_CRC 0x0020u
  ------------------
 1014|     84|        st.size = cdir->size;
 1015|     84|        st.crc = crc_should;
 1016|     84|        if ((src_window = _zip_source_window_new(za->src, cdir->offset, cdir->size, &st, 0, NULL, NULL, NULL, 0, false, NULL)) == NULL) {
  ------------------
  |  Branch (1016:13): [True: 0, False: 84]
  ------------------
 1017|      0|            return;
 1018|      0|        }
 1019|     84|        if ((src_crc = zip_source_crc_create(src_window, 1, NULL)) == NULL) {
  ------------------
  |  Branch (1019:13): [True: 0, False: 84]
  ------------------
 1020|      0|            zip_source_free(src_window);
 1021|      0|            return;
 1022|      0|        }
 1023|     84|        if (zip_source_open(src_crc) != 0) {
  ------------------
  |  Branch (1023:13): [True: 0, False: 84]
  ------------------
 1024|      0|            zip_source_free(src_crc);
 1025|      0|            return;
 1026|      0|        }
 1027|    129|        while ((ret = zip_source_read(src_crc, buffer, sizeof(buffer))) > 0) {
  ------------------
  |  Branch (1027:16): [True: 45, False: 84]
  ------------------
 1028|     45|        }
 1029|     84|        zip_source_free(src_crc);
 1030|     84|        if (ret < 0) {
  ------------------
  |  Branch (1030:13): [True: 83, False: 1]
  ------------------
 1031|     83|            return;
 1032|     83|        }
 1033|     84|    }
 1034|       |
 1035|       |    /* TODO: if check consistency, check cdir entries for valid values */
 1036|      1|    za->flags |= ZIP_AFL_IS_TORRENTZIP;
  ------------------
  |  |  114|      1|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  ------------------
 1037|      1|}
zip_open.c:decode_hex:
  964|    808|static int decode_hex(char c) {
  965|    808|    if (c >= '0' && c <= '9') {
  ------------------
  |  Branch (965:9): [True: 785, False: 23]
  |  Branch (965:21): [True: 528, False: 257]
  ------------------
  966|    528|        return c - '0';
  967|    528|    }
  968|    280|    else if (c >= 'A' && c <= 'F') {
  ------------------
  |  Branch (968:14): [True: 251, False: 29]
  |  Branch (968:26): [True: 237, False: 14]
  ------------------
  969|    237|        return c - 'A' + 10;
  970|    237|    }
  971|     43|    else {
  972|     43|        return -1;
  973|     43|    }
  974|    808|}

_zip_progress_free:
   72|  3.72k|void _zip_progress_free(zip_progress_t *progress) {
   73|  3.72k|    if (progress == NULL) {
  ------------------
  |  Branch (73:9): [True: 3.72k, False: 0]
  ------------------
   74|  3.72k|        return;
   75|  3.72k|    }
   76|       |
   77|      0|    _zip_progress_free_progress_callback(progress);
   78|      0|    _zip_progress_free_cancel_callback(progress);
   79|       |
   80|      0|    free(progress);
   81|      0|}

zip_realloc:
   38|  9.31k|bool zip_realloc(void **memory, zip_uint64_t *alloced_elements, zip_uint64_t element_size, zip_uint64_t additional_elements, zip_error_t *error) {
   39|  9.31k|    zip_uint64_t new_alloced_elements;
   40|  9.31k|    void *new_memory;
   41|       |
   42|  9.31k|    if (additional_elements == 0) {
  ------------------
  |  Branch (42:9): [True: 0, False: 9.31k]
  ------------------
   43|      0|        return true;
   44|      0|    }
   45|       |
   46|  9.31k|    new_alloced_elements = *alloced_elements + additional_elements;
   47|       |
   48|  9.31k|    if (new_alloced_elements < additional_elements || new_alloced_elements > SIZE_MAX / element_size) {
  ------------------
  |  Branch (48:9): [True: 0, False: 9.31k]
  |  Branch (48:55): [True: 0, False: 9.31k]
  ------------------
   49|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   50|      0|        return false;
   51|      0|    }
   52|       |
   53|  9.31k|    if ((new_memory = realloc(*memory, (size_t)(new_alloced_elements * element_size))) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 9.31k]
  ------------------
   54|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   55|      0|        return false;
   56|      0|    }
   57|       |
   58|  9.31k|    *memory = new_memory;
   59|  9.31k|    *alloced_elements = new_alloced_elements;
   60|       |
   61|       |    return true;
   62|  9.31k|}

zip_source_at_eof:
    3|     84|ZIP_EXTERN int zip_source_at_eof(zip_source_t *src) {
    4|     84|    zip_uint8_t d[1];
    5|     84|    zip_int64_t n;
    6|       |
    7|     84|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|     84|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (7:9): [True: 0, False: 84]
  ------------------
    8|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
    9|      0|        return -1;
   10|      0|    }
   11|       |
   12|     84|    if (!src->eof) {
  ------------------
  |  Branch (12:9): [True: 0, False: 84]
  ------------------
   13|      0|        if (src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_AT_EOF)) {
  ------------------
  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (13:13): [True: 0, False: 0]
  ------------------
   14|      0|            n = _zip_source_call(src, NULL, 0, ZIP_SOURCE_AT_EOF);
   15|      0|            if (n < 0) {
  ------------------
  |  Branch (15:17): [True: 0, False: 0]
  ------------------
   16|      0|                return -1;
   17|      0|            }
   18|      0|            if (n != 0) {
  ------------------
  |  Branch (18:17): [True: 0, False: 0]
  ------------------
   19|      0|                src->eof = true;
   20|      0|            }
   21|      0|        }
   22|      0|        else {
   23|      0|            n = zip_source_read(src, d, sizeof(d));
   24|      0|            if (n < 0) {
  ------------------
  |  Branch (24:17): [True: 0, False: 0]
  ------------------
   25|      0|                return -1;
   26|      0|            }
   27|      0|            if (n > 0) {
  ------------------
  |  Branch (27:17): [True: 0, False: 0]
  ------------------
   28|      0|                if (src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) {
  ------------------
  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (28:21): [True: 0, False: 0]
  ------------------
   29|      0|                    if (zip_source_seek(src, -1, SEEK_CUR) < 0) {
  ------------------
  |  Branch (29:25): [True: 0, False: 0]
  ------------------
   30|      0|                        return -1;
   31|      0|                    }
   32|      0|                }
   33|      0|                else {
   34|      0|                    src->have_next_byte = true;
   35|      0|                    src->next_byte = d[0];
   36|      0|                    src->bytes_read -= 1;
   37|      0|                }
   38|      0|            }
   39|      0|        }
   40|      0|    }
   41|       |
   42|     84|    return src->eof ? 1 : 0;
  ------------------
  |  Branch (42:12): [True: 84, False: 0]
  ------------------
   43|     84|}

zip_source_buffer_create:
   97|  3.72k|ZIP_EXTERN zip_source_t *zip_source_buffer_create(const void *data, zip_uint64_t len, int freep, zip_error_t *error) {
   98|       |    return zip_source_buffer_with_attributes_create(data, len, freep, NULL, error);
   99|  3.72k|}
zip_source_buffer_with_attributes_create:
  102|  3.72k|zip_source_t *zip_source_buffer_with_attributes_create(const void *data, zip_uint64_t len, int freep, zip_file_attributes_t *attributes, zip_error_t *error) {
  103|  3.72k|    zip_buffer_fragment_t fragment;
  104|       |
  105|  3.72k|    if (data == NULL) {
  ------------------
  |  Branch (105:9): [True: 0, False: 3.72k]
  ------------------
  106|      0|        if (len > 0) {
  ------------------
  |  Branch (106:13): [True: 0, False: 0]
  ------------------
  107|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  108|      0|            return NULL;
  109|      0|        }
  110|       |
  111|      0|        return zip_source_buffer_fragment_with_attributes_create(NULL, 0, freep, attributes, error);
  112|      0|    }
  113|       |
  114|  3.72k|    fragment.data = (zip_uint8_t *)data;
  115|  3.72k|    fragment.length = len;
  116|       |
  117|  3.72k|    return zip_source_buffer_fragment_with_attributes_create(&fragment, 1, freep, attributes, error);
  118|  3.72k|}
zip_source_buffer_fragment_with_attributes_create:
  134|  3.72k|zip_source_t *zip_source_buffer_fragment_with_attributes_create(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep, zip_file_attributes_t *attributes, zip_error_t *error) {
  135|  3.72k|    struct read_data *ctx;
  136|  3.72k|    zip_source_t *zs;
  137|  3.72k|    buffer_t *buffer;
  138|       |
  139|  3.72k|    if (fragments == NULL && nfragments > 0) {
  ------------------
  |  Branch (139:9): [True: 0, False: 3.72k]
  |  Branch (139:30): [True: 0, False: 0]
  ------------------
  140|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|       |
  144|  3.72k|    if ((buffer = buffer_new(fragments, nfragments, freep, error)) == NULL) {
  ------------------
  |  Branch (144:9): [True: 0, False: 3.72k]
  ------------------
  145|      0|        return NULL;
  146|      0|    }
  147|       |
  148|  3.72k|    if ((ctx = (struct read_data *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 3.72k]
  ------------------
  149|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  150|      0|        buffer_free(buffer);
  151|      0|        return NULL;
  152|      0|    }
  153|       |
  154|  3.72k|    ctx->in = buffer;
  155|  3.72k|    ctx->out = NULL;
  156|  3.72k|    ctx->mtime = time(NULL);
  157|  3.72k|    if (attributes) {
  ------------------
  |  Branch (157:9): [True: 0, False: 3.72k]
  ------------------
  158|      0|        (void)memcpy_s(&ctx->attributes, sizeof(ctx->attributes), attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  159|      0|    }
  160|  3.72k|    else {
  161|  3.72k|        zip_file_attributes_init(&ctx->attributes);
  162|  3.72k|    }
  163|  3.72k|    zip_error_init(&ctx->error);
  164|       |
  165|  3.72k|    if ((zs = zip_source_function_create(read_data, ctx, error)) == NULL) {
  ------------------
  |  Branch (165:9): [True: 0, False: 3.72k]
  ------------------
  166|      0|        buffer_free(ctx->in);
  167|      0|        free(ctx);
  168|      0|        return NULL;
  169|      0|    }
  170|       |
  171|  3.72k|    return zs;
  172|  3.72k|}
zip_source_buffer.c:read_data:
  179|   502k|static zip_int64_t read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  180|   502k|    struct read_data *ctx = (struct read_data *)state;
  181|       |
  182|   502k|    switch (cmd) {
  183|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (183:5): [True: 0, False: 502k]
  ------------------
  184|      0|        return buffer_at_eof(ctx->in);
  185|       |
  186|      0|    case ZIP_SOURCE_BEGIN_WRITE:
  ------------------
  |  Branch (186:5): [True: 0, False: 502k]
  ------------------
  187|      0|        if ((ctx->out = buffer_new(NULL, 0, 0, &ctx->error)) == NULL) {
  ------------------
  |  Branch (187:13): [True: 0, False: 0]
  ------------------
  188|      0|            return -1;
  189|      0|        }
  190|      0|        ctx->out->offset = 0;
  191|      0|        ctx->out->current_fragment = 0;
  192|      0|        return 0;
  193|       |
  194|      0|    case ZIP_SOURCE_BEGIN_WRITE_CLONING:
  ------------------
  |  Branch (194:5): [True: 0, False: 502k]
  ------------------
  195|      0|        if ((ctx->out = buffer_clone(ctx->in, len, &ctx->error)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 0, False: 0]
  ------------------
  196|      0|            return -1;
  197|      0|        }
  198|      0|        ctx->out->offset = len;
  199|      0|        ctx->out->current_fragment = ctx->out->nfragments;
  200|      0|        return 0;
  201|       |
  202|  3.72k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (202:5): [True: 3.72k, False: 499k]
  ------------------
  203|  3.72k|        return 0;
  204|       |
  205|      0|    case ZIP_SOURCE_COMMIT_WRITE:
  ------------------
  |  Branch (205:5): [True: 0, False: 502k]
  ------------------
  206|      0|        buffer_free(ctx->in);
  207|      0|        ctx->in = ctx->out;
  208|      0|        ctx->out = NULL;
  209|      0|        return 0;
  210|       |
  211|  91.7k|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (211:5): [True: 91.7k, False: 411k]
  ------------------
  212|  91.7k|        return zip_error_to_data(&ctx->error, data, len);
  213|       |
  214|  3.72k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (214:5): [True: 3.72k, False: 499k]
  ------------------
  215|  3.72k|        buffer_free(ctx->in);
  216|  3.72k|        buffer_free(ctx->out);
  217|  3.72k|        free(ctx);
  218|  3.72k|        return 0;
  219|       |
  220|      0|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (220:5): [True: 0, False: 502k]
  ------------------
  221|      0|        if (len < sizeof(ctx->attributes)) {
  ------------------
  |  Branch (221:13): [True: 0, False: 0]
  ------------------
  222|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  223|      0|            return -1;
  224|      0|        }
  225|       |
  226|      0|        (void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  227|       |
  228|      0|        return sizeof(ctx->attributes);
  229|      0|    }
  230|       |
  231|  3.72k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (231:5): [True: 3.72k, False: 499k]
  ------------------
  232|  3.72k|        ctx->in->offset = 0;
  233|  3.72k|        ctx->in->current_fragment = 0;
  234|  3.72k|        return 0;
  235|       |
  236|   206k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (236:5): [True: 206k, False: 296k]
  ------------------
  237|   206k|        if (len > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   206k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (237:13): [True: 0, False: 206k]
  ------------------
  238|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  239|      0|            return -1;
  240|      0|        }
  241|   206k|        return buffer_read(ctx->in, data, len);
  242|       |
  243|      0|    case ZIP_SOURCE_REMOVE: {
  ------------------
  |  Branch (243:5): [True: 0, False: 502k]
  ------------------
  244|      0|        buffer_t *empty = buffer_new(NULL, 0, 0, &ctx->error);
  245|      0|        if (empty == NULL) {
  ------------------
  |  Branch (245:13): [True: 0, False: 0]
  ------------------
  246|      0|            return -1;
  247|      0|        }
  248|       |
  249|      0|        buffer_free(ctx->in);
  250|      0|        ctx->in = empty;
  251|      0|        return 0;
  252|      0|    }
  253|       |
  254|      0|    case ZIP_SOURCE_ROLLBACK_WRITE:
  ------------------
  |  Branch (254:5): [True: 0, False: 502k]
  ------------------
  255|      0|        buffer_free(ctx->out);
  256|      0|        ctx->out = NULL;
  257|      0|        return 0;
  258|       |
  259|   178k|    case ZIP_SOURCE_SEEK:
  ------------------
  |  Branch (259:5): [True: 178k, False: 324k]
  ------------------
  260|   178k|        return buffer_seek(ctx->in, data, len, &ctx->error);
  261|       |
  262|      0|    case ZIP_SOURCE_SEEK_WRITE:
  ------------------
  |  Branch (262:5): [True: 0, False: 502k]
  ------------------
  263|      0|        return buffer_seek(ctx->out, data, len, &ctx->error);
  264|       |
  265|  7.61k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (265:5): [True: 7.61k, False: 495k]
  ------------------
  266|  7.61k|        zip_stat_t *st;
  267|       |
  268|  7.61k|        if (len < sizeof(*st)) {
  ------------------
  |  Branch (268:13): [True: 0, False: 7.61k]
  ------------------
  269|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  270|      0|            return -1;
  271|      0|        }
  272|       |
  273|  7.61k|        st = (zip_stat_t *)data;
  274|       |
  275|  7.61k|        zip_stat_init(st);
  276|  7.61k|        st->mtime = ctx->mtime;
  277|  7.61k|        st->size = ctx->in->size;
  278|  7.61k|        st->comp_size = st->size;
  279|  7.61k|        st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|  7.61k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  280|  7.61k|        st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  7.61k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  281|  7.61k|        st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  327|  7.61k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  325|  7.61k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|  7.61k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|  7.61k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  7.61k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  282|       |
  283|  7.61k|        return sizeof(*st);
  284|  7.61k|    }
  285|       |
  286|  3.72k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (286:5): [True: 3.72k, False: 499k]
  ------------------
  287|  3.72k|        return zip_source_make_command_bitmap(ZIP_SOURCE_AT_EOF, ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_BEGIN_WRITE_CLONING, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  288|       |
  289|  3.84k|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (289:5): [True: 3.84k, False: 499k]
  ------------------
  290|  3.84k|        if (ctx->in->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  3.84k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (290:13): [True: 0, False: 3.84k]
  ------------------
  291|      0|            zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
  292|      0|            return -1;
  293|      0|        }
  294|  3.84k|        return (zip_int64_t)ctx->in->offset;
  295|       |
  296|       |
  297|      0|    case ZIP_SOURCE_TELL_WRITE:
  ------------------
  |  Branch (297:5): [True: 0, False: 502k]
  ------------------
  298|      0|        if (ctx->out->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (298:13): [True: 0, False: 0]
  ------------------
  299|      0|            zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
  300|      0|            return -1;
  301|      0|        }
  302|      0|        return (zip_int64_t)ctx->out->offset;
  303|       |
  304|      0|    case ZIP_SOURCE_WRITE:
  ------------------
  |  Branch (304:5): [True: 0, False: 502k]
  ------------------
  305|      0|        if (len > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (305:13): [True: 0, False: 0]
  ------------------
  306|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  307|      0|            return -1;
  308|      0|        }
  309|      0|        return buffer_write(ctx->out, data, len, &ctx->error);
  310|       |
  311|      0|    default:
  ------------------
  |  Branch (311:5): [True: 0, False: 502k]
  ------------------
  312|      0|        zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
  313|      0|        return -1;
  314|   502k|    }
  315|   502k|}
zip_source_buffer.c:buffer_find_fragment:
  373|  86.3k|static zip_uint64_t buffer_find_fragment(const buffer_t *buffer, zip_uint64_t offset) {
  374|  86.3k|    zip_uint64_t low, high, mid;
  375|       |
  376|  86.3k|    if (buffer->nfragments == 0) {
  ------------------
  |  Branch (376:9): [True: 0, False: 86.3k]
  ------------------
  377|      0|        return 0;
  378|      0|    }
  379|       |
  380|  86.3k|    low = 0;
  381|  86.3k|    high = buffer->nfragments - 1;
  382|       |
  383|  86.3k|    while (low < high) {
  ------------------
  |  Branch (383:12): [True: 0, False: 86.3k]
  ------------------
  384|      0|        mid = (high - low) / 2 + low;
  385|      0|        if (buffer->fragment_offsets[mid] > offset) {
  ------------------
  |  Branch (385:13): [True: 0, False: 0]
  ------------------
  386|      0|            high = mid - 1;
  387|      0|        }
  388|      0|        else if (mid == buffer->nfragments || buffer->fragment_offsets[mid + 1] > offset) {
  ------------------
  |  Branch (388:18): [True: 0, False: 0]
  |  Branch (388:47): [True: 0, False: 0]
  ------------------
  389|      0|            return mid;
  390|      0|        }
  391|      0|        else {
  392|      0|            low = mid + 1;
  393|      0|        }
  394|      0|    }
  395|       |
  396|  86.3k|    return low;
  397|  86.3k|}
zip_source_buffer.c:buffer_read:
  514|   206k|static zip_int64_t buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
  515|   206k|    zip_uint64_t n, i, fragment_offset;
  516|       |
  517|   206k|    length = ZIP_MIN(length, buffer->size - buffer->offset);
  ------------------
  |  |  515|   206k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 184k, False: 22.4k]
  |  |  ------------------
  ------------------
  518|       |
  519|   206k|    if (length == 0) {
  ------------------
  |  Branch (519:9): [True: 9.29k, False: 197k]
  ------------------
  520|  9.29k|        return 0;
  521|  9.29k|    }
  522|   197k|    if (length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   197k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (522:9): [True: 0, False: 197k]
  ------------------
  523|      0|        return -1;
  524|      0|    }
  525|       |
  526|   197k|    i = buffer->current_fragment;
  527|   197k|    fragment_offset = buffer->offset - buffer->fragment_offsets[i];
  528|   197k|    n = 0;
  529|   394k|    while (n < length) {
  ------------------
  |  Branch (529:12): [True: 197k, False: 197k]
  ------------------
  530|   197k|        zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
  ------------------
  |  |  515|   197k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 184k, False: 13.1k]
  |  |  ------------------
  ------------------
  531|       |#if ZIP_UINT64_MAX > SIZE_MAX
  532|       |        left = ZIP_MIN(left, SIZE_MAX);
  533|       |#endif
  534|       |
  535|   197k|        (void)memcpy_s(data + n, (size_t)left, buffer->fragments[i].data + fragment_offset, (size_t)left);
  ------------------
  |  |  202|   197k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  536|       |
  537|   197k|        if (left == buffer->fragments[i].length - fragment_offset) {
  ------------------
  |  Branch (537:13): [True: 13.1k, False: 184k]
  ------------------
  538|  13.1k|            i++;
  539|  13.1k|        }
  540|   197k|        n += left;
  541|   197k|        fragment_offset = 0;
  542|   197k|    }
  543|       |
  544|   197k|    buffer->offset += n;
  545|   197k|    buffer->current_fragment = i;
  546|   197k|    return (zip_int64_t)n;
  547|   197k|}
zip_source_buffer.c:buffer_seek:
  550|   178k|static int buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error) {
  551|   178k|    zip_int64_t new_offset = zip_source_seek_compute_offset(buffer->offset, buffer->size, data, len, error);
  552|       |
  553|   178k|    if (new_offset < 0) {
  ------------------
  |  Branch (553:9): [True: 91.7k, False: 86.3k]
  ------------------
  554|  91.7k|        return -1;
  555|  91.7k|    }
  556|       |
  557|  86.3k|    buffer->offset = (zip_uint64_t)new_offset;
  558|  86.3k|    buffer->current_fragment = buffer_find_fragment(buffer, buffer->offset);
  559|  86.3k|    return 0;
  560|   178k|}
zip_source_buffer.c:buffer_grow_fragments:
  423|  3.72k|static bool buffer_grow_fragments(buffer_t *buffer, zip_uint64_t capacity, zip_error_t *error) {
  424|  3.72k|    zip_uint64_t additional_fragments;
  425|  3.72k|    zip_uint64_t offset_capacity = buffer->fragments_capacity + 1;
  426|       |
  427|  3.72k|    if (capacity <= buffer->fragments_capacity) {
  ------------------
  |  Branch (427:9): [True: 0, False: 3.72k]
  ------------------
  428|      0|        return true;
  429|      0|    }
  430|       |
  431|  3.72k|    additional_fragments = capacity - buffer->fragments_capacity;
  432|       |
  433|  3.72k|    if (!ZIP_REALLOC(buffer->fragments, buffer->fragments_capacity, additional_fragments, error)) {
  ------------------
  |  |  107|  3.72k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (433:9): [True: 0, False: 3.72k]
  ------------------
  434|      0|        return false;
  435|      0|    }
  436|       |    /* The size of both buffer->fragments and buffer->fragment_offsets is stored in buffer->fragments_capacity, so use a temporary capacity variable here for reallocating buffer->fragment_offsets. */
  437|  3.72k|    if (!ZIP_REALLOC(buffer->fragment_offsets, offset_capacity, additional_fragments, error)) {
  ------------------
  |  |  107|  3.72k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (437:9): [True: 0, False: 3.72k]
  ------------------
  438|      0|        buffer->fragments_capacity -= additional_fragments;
  439|      0|        return false;
  440|      0|    }
  441|       |
  442|  3.72k|    return true;
  443|  3.72k|}
zip_source_buffer.c:buffer_free:
  400|  7.44k|static void buffer_free(buffer_t *buffer) {
  401|  7.44k|    zip_uint64_t i;
  402|       |
  403|  7.44k|    if (buffer == NULL) {
  ------------------
  |  Branch (403:9): [True: 3.72k, False: 3.72k]
  ------------------
  404|  3.72k|        return;
  405|  3.72k|    }
  406|       |
  407|  3.72k|    if (buffer->shared_buffer != NULL) {
  ------------------
  |  Branch (407:9): [True: 0, False: 3.72k]
  ------------------
  408|      0|        buffer->shared_buffer->shared_buffer = NULL;
  409|      0|        buffer->shared_buffer->shared_fragments = 0;
  410|       |
  411|      0|        buffer->first_owned_fragment = ZIP_MAX(buffer->first_owned_fragment, buffer->shared_fragments);
  ------------------
  |  |  514|      0|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (514:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  412|      0|    }
  413|       |
  414|  3.72k|    for (i = buffer->first_owned_fragment; i < buffer->nfragments; i++) {
  ------------------
  |  Branch (414:44): [True: 0, False: 3.72k]
  ------------------
  415|      0|        free(buffer->fragments[i].data);
  416|      0|    }
  417|  3.72k|    free(buffer->fragments);
  418|  3.72k|    free(buffer->fragment_offsets);
  419|  3.72k|    free(buffer);
  420|  3.72k|}
zip_source_buffer.c:buffer_new:
  446|  3.72k|static buffer_t *buffer_new(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int free_data, zip_error_t *error) {
  447|  3.72k|    buffer_t *buffer;
  448|       |
  449|  3.72k|    if ((buffer = malloc(sizeof(*buffer))) == NULL) {
  ------------------
  |  Branch (449:9): [True: 0, False: 3.72k]
  ------------------
  450|      0|        return NULL;
  451|      0|    }
  452|       |
  453|  3.72k|    buffer->offset = 0;
  454|  3.72k|    buffer->first_owned_fragment = 0;
  455|  3.72k|    buffer->size = 0;
  456|  3.72k|    buffer->fragments = NULL;
  457|  3.72k|    buffer->fragment_offsets = NULL;
  458|  3.72k|    buffer->nfragments = 0;
  459|  3.72k|    buffer->fragments_capacity = 0;
  460|  3.72k|    buffer->shared_buffer = NULL;
  461|  3.72k|    buffer->shared_fragments = 0;
  462|       |
  463|  3.72k|    if (nfragments == 0) {
  ------------------
  |  Branch (463:9): [True: 0, False: 3.72k]
  ------------------
  464|      0|        if ((buffer->fragment_offsets = malloc(sizeof(buffer->fragment_offsets[0]))) == NULL) {
  ------------------
  |  Branch (464:13): [True: 0, False: 0]
  ------------------
  465|      0|            free(buffer);
  466|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  467|      0|            return NULL;
  468|      0|        }
  469|      0|        buffer->fragment_offsets[0] = 0;
  470|      0|    }
  471|  3.72k|    else {
  472|  3.72k|        zip_uint64_t i, j, offset;
  473|       |
  474|  3.72k|        if (!buffer_grow_fragments(buffer, nfragments, NULL)) {
  ------------------
  |  Branch (474:13): [True: 0, False: 3.72k]
  ------------------
  475|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  476|      0|            buffer_free(buffer);
  477|      0|            return NULL;
  478|      0|        }
  479|       |
  480|  3.72k|        offset = 0;
  481|  7.44k|        for (i = 0, j = 0; i < nfragments; i++) {
  ------------------
  |  Branch (481:28): [True: 3.72k, False: 3.72k]
  ------------------
  482|  3.72k|            if (fragments[i].length == 0) {
  ------------------
  |  Branch (482:17): [True: 0, False: 3.72k]
  ------------------
  483|      0|                continue;
  484|      0|            }
  485|  3.72k|            if (fragments[i].data == NULL) {
  ------------------
  |  Branch (485:17): [True: 0, False: 3.72k]
  ------------------
  486|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  487|      0|                buffer_free(buffer);
  488|      0|                return NULL;
  489|      0|            }
  490|  3.72k|            buffer->fragments[j].data = fragments[i].data;
  491|  3.72k|            buffer->fragments[j].length = fragments[i].length;
  492|  3.72k|            buffer->fragment_offsets[j] = offset;
  493|  3.72k|            if (offset + fragments[i].length < offset) {
  ------------------
  |  Branch (493:17): [True: 0, False: 3.72k]
  ------------------
  494|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  495|      0|                buffer_free(buffer);
  496|      0|                return NULL;
  497|      0|            }
  498|  3.72k|            offset += fragments[i].length;
  499|  3.72k|            j++;
  500|  3.72k|        }
  501|  3.72k|        buffer->nfragments = j;
  502|  3.72k|        buffer->first_owned_fragment = free_data ? 0 : buffer->nfragments;
  ------------------
  |  Branch (502:40): [True: 0, False: 3.72k]
  ------------------
  503|  3.72k|        buffer->fragment_offsets[buffer->nfragments] = offset;
  504|  3.72k|        buffer->size = offset;
  505|  3.72k|    }
  506|       |
  507|  3.72k|    return buffer;
  508|  3.72k|}

_zip_source_call:
   38|   500k|zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command) {
   39|   500k|    zip_int64_t ret;
   40|       |
   41|   500k|    if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) {
  ------------------
  |  |  276|   500k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (41:9): [True: 0, False: 500k]
  ------------------
   42|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|   500k|    if (src->src == NULL) {
  ------------------
  |  Branch (46:9): [True: 499k, False: 1.09k]
  ------------------
   47|   499k|        ret = src->cb.f(src->ud, data, length, command);
   48|   499k|    }
   49|  1.09k|    else {
   50|  1.09k|        ret = src->cb.l(src->src, src->ud, data, length, command);
   51|  1.09k|    }
   52|       |
   53|   500k|    if (ret < 0) {
  ------------------
  |  Branch (53:9): [True: 91.9k, False: 408k]
  ------------------
   54|  91.9k|        if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) {
  ------------------
  |  Branch (54:13): [True: 91.9k, False: 0]
  |  Branch (54:44): [True: 91.9k, False: 0]
  ------------------
   55|  91.9k|            _zip_source_get_error(src);
   56|  91.9k|        }
   57|  91.9k|    }
   58|       |
   59|   500k|    return ret;
   60|   500k|}
_zip_source_get_error:
   62|  91.9k|void _zip_source_get_error(zip_source_t *src) {
   63|  91.9k|    int e[2];
   64|       |
   65|  91.9k|    if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) {
  ------------------
  |  Branch (65:9): [True: 0, False: 91.9k]
  ------------------
   66|      0|        zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   67|      0|    }
   68|  91.9k|    else {
   69|  91.9k|        zip_error_set(&src->error, e[0], e[1]);
   70|  91.9k|    }
   71|  91.9k|}

zip_source_close:
   38|  6.49k|int zip_source_close(zip_source_t *src) {
   39|  6.49k|    int ret = 0;
   40|       |
   41|  6.49k|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  6.49k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (41:9): [True: 2.51k, False: 3.97k]
  ------------------
   42|  2.51k|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|  2.51k|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   43|  2.51k|        return -1;
   44|  2.51k|    }
   45|       |
   46|  3.97k|    src->open_count--;
   47|  3.97k|    if (src->open_count == 0) {
  ------------------
  |  Branch (47:9): [True: 3.88k, False: 84]
  ------------------
   48|  3.88k|        src->have_next_byte = false;
   49|       |
   50|  3.88k|        if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE) < 0) {
  ------------------
  |  Branch (50:13): [True: 83, False: 3.80k]
  ------------------
   51|     83|            ret = -1;
   52|     83|        }
   53|       |
   54|  3.88k|        if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|  3.88k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 168, False: 3.72k]
  |  |  ------------------
  ------------------
   55|    168|            if (!ZIP_SOURCE_IS_OPEN_READING(src->src)) {
  ------------------
  |  |  441|    168|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (55:17): [True: 0, False: 168]
  ------------------
   56|      0|                if (ret == 0) {
  ------------------
  |  Branch (56:21): [True: 0, False: 0]
  ------------------
   57|      0|                    zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   58|      0|                }
   59|      0|                return -1;
   60|      0|            }
   61|    168|            if (zip_source_close(src->src) < 0) {
  ------------------
  |  Branch (61:17): [True: 0, False: 168]
  ------------------
   62|      0|                if (ret == 0) {
  ------------------
  |  Branch (62:21): [True: 0, False: 0]
  ------------------
   63|      0|                    zip_error_set_from_source(&src->error, src->src);
   64|      0|                }
   65|      0|                ret = -1;
   66|      0|            }
   67|    168|        }
   68|  3.88k|    }
   69|       |
   70|  3.97k|    return ret;
   71|  3.97k|}

zip_source_crc_create:
   54|     84|zip_source_t *zip_source_crc_create(zip_source_t *src, int validate, zip_error_t *error) {
   55|     84|    struct crc_context *ctx;
   56|     84|    zip_source_t *new_src;
   57|       |
   58|     84|    if (src == NULL) {
  ------------------
  |  Branch (58:9): [True: 0, False: 84]
  ------------------
   59|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   60|      0|        return NULL;
   61|      0|    }
   62|       |
   63|     84|    if ((ctx = (struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (63:9): [True: 0, False: 84]
  ------------------
   64|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   65|      0|        return NULL;
   66|      0|    }
   67|       |
   68|     84|    zip_error_init(&ctx->error);
   69|     84|    ctx->validate = validate;
   70|     84|    ctx->crc_complete = 0;
   71|     84|    ctx->crc_position = 0;
   72|     84|    ctx->crc = (zip_uint32_t)crc32(0, NULL, 0);
   73|     84|    ctx->size = 0;
   74|       |
   75|     84|    new_src = zip_source_layered_create(src, crc_read, ctx, error);
   76|     84|    if (new_src == NULL) {
  ------------------
  |  Branch (76:9): [True: 0, False: 84]
  ------------------
   77|      0|        free(ctx);
   78|      0|        return NULL;
   79|      0|    }
   80|     84|    return new_src;
   81|     84|}
zip_source_crc.c:crc_read:
   84|    631|static zip_int64_t crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
   85|    631|    struct crc_context *ctx;
   86|    631|    zip_int64_t n;
   87|       |
   88|    631|    ctx = (struct crc_context *)_ctx;
   89|       |
   90|    631|    switch (cmd) {
   91|     84|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (91:5): [True: 84, False: 547]
  ------------------
   92|     84|        ctx->position = 0;
   93|     84|        return 0;
   94|       |
   95|    129|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (95:5): [True: 129, False: 502]
  ------------------
   96|    129|        if ((n = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (96:13): [True: 0, False: 129]
  ------------------
   97|      0|            zip_error_set_from_source(&ctx->error, src);
   98|      0|            return -1;
   99|      0|        }
  100|       |
  101|    129|        if (n == 0) {
  ------------------
  |  Branch (101:13): [True: 84, False: 45]
  ------------------
  102|     84|            return validate_crc(ctx, src);
  103|     84|        }
  104|     45|        else {
  105|       |            /*
  106|       |             We can only compute the CRC data in the correct order. So we update the CRC for data read this time that starts at ctx->crc_position.
  107|       |
  108|       |             If we already computed the CRC for the whole file, or if there is a gap between ctx->crc_position and the start of new data, or if we already computed the CRC for all new data read, we don't update the CRC.
  109|       |
  110|       |             ctx->position is the position of the first byte in data.
  111|       |
  112|       |             ctx->crc_position is the position of the first byte in data that has not been included  in the CRC yet.
  113|       |
  114|       |             Therefore, we want to compute the CRC for data[ctx->crc_position - ctx->position .. n-1].
  115|       |
  116|       |            */
  117|     45|            if (!ctx->crc_complete && ctx->position <= ctx->crc_position && ctx->crc_position < ctx->position + (zip_uint64_t)n) {
  ------------------
  |  Branch (117:17): [True: 45, False: 0]
  |  Branch (117:39): [True: 45, False: 0]
  |  Branch (117:77): [True: 45, False: 0]
  ------------------
  118|     45|                zip_uint64_t i, nn;
  119|       |
  120|     90|                for (i = ctx->crc_position - ctx->position; i < (zip_uint64_t)n; i += nn) {
  ------------------
  |  Branch (120:61): [True: 45, False: 45]
  ------------------
  121|     45|                    nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n - i);
  ------------------
  |  |  515|     45|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 45]
  |  |  ------------------
  ------------------
  122|       |
  123|     45|                    ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data + i, (uInt)nn);
  124|     45|                    ctx->crc_position += nn;
  125|     45|                }
  126|     45|            }
  127|     45|        }
  128|     45|        ctx->position += (zip_uint64_t)n;
  129|     45|        return n;
  130|       |
  131|     84|    case ZIP_SOURCE_CLOSE: {
  ------------------
  |  Branch (131:5): [True: 84, False: 547]
  ------------------
  132|     84|        zip_int64_t ret = zip_source_at_eof(src);
  133|     84|        if (ret < 0) {
  ------------------
  |  Branch (133:13): [True: 0, False: 84]
  ------------------
  134|      0|            zip_error_set_from_source(&ctx->error, src);
  135|      0|            return -1;
  136|      0|        }
  137|     84|        else if (ret == 1) {
  ------------------
  |  Branch (137:18): [True: 84, False: 0]
  ------------------
  138|     84|            return validate_crc(ctx, src);
  139|     84|        }
  140|      0|        else {
  141|      0|            return 0;
  142|      0|        }
  143|     84|    }
  144|       |
  145|      0|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (145:5): [True: 0, False: 631]
  ------------------
  146|      0|        zip_stat_t *st;
  147|       |
  148|      0|        st = (zip_stat_t *)data;
  149|       |
  150|      0|        if (ctx->crc_complete) {
  ------------------
  |  Branch (150:13): [True: 0, False: 0]
  ------------------
  151|      0|            if ((st->valid & ZIP_STAT_SIZE) && st->size != ctx->size) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (151:17): [True: 0, False: 0]
  |  Branch (151:48): [True: 0, False: 0]
  ------------------
  152|      0|                zip_error_set(&ctx->error, ZIP_ER_DATA_LENGTH, 0);
  ------------------
  |  |  164|      0|#define ZIP_ER_DATA_LENGTH 33     /* N Unexpected length of data */
  ------------------
  153|      0|                return -1;
  154|      0|            }
  155|       |            /* TODO: Set comp_size, comp_method, encryption_method?
  156|       |                    After all, this only works for uncompressed data. */
  157|      0|            st->size = ctx->size;
  158|      0|            st->crc = ctx->crc;
  159|      0|            st->comp_size = ctx->size;
  160|      0|            st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  161|      0|            st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|      0|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  162|      0|            st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  328|      0|#define ZIP_STAT_CRC 0x0020u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|      0|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  163|      0|        }
  164|      0|        return 0;
  165|      0|    }
  166|       |
  167|    166|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (167:5): [True: 166, False: 465]
  ------------------
  168|    166|        return zip_error_to_data(&ctx->error, data, len);
  169|       |
  170|     84|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (170:5): [True: 84, False: 547]
  ------------------
  171|     84|        free(ctx);
  172|     84|        return 0;
  173|       |
  174|     84|    case ZIP_SOURCE_SUPPORTS: {
  ------------------
  |  Branch (174:5): [True: 84, False: 547]
  ------------------
  175|     84|        zip_int64_t mask = zip_source_supports(src);
  176|       |
  177|     84|        if (mask < 0) {
  ------------------
  |  Branch (177:13): [True: 0, False: 84]
  ------------------
  178|      0|            zip_error_set_from_source(&ctx->error, src);
  179|      0|            return -1;
  180|      0|        }
  181|       |
  182|     84|        mask &= ~zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
  183|     84|        mask |= zip_source_make_command_bitmap(ZIP_SOURCE_FREE, -1);
  184|     84|        return mask;
  185|     84|    }
  186|       |
  187|      0|    case ZIP_SOURCE_SEEK: {
  ------------------
  |  Branch (187:5): [True: 0, False: 631]
  ------------------
  188|      0|        zip_int64_t new_position;
  189|      0|        zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
  ------------------
  |  |  312|      0|#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
  |  |  ------------------
  |  |  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  |  |  ------------------
  |  |  |  Branch (312:54): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  190|       |
  191|      0|        if (args == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  ------------------
  192|      0|            return -1;
  193|      0|        }
  194|      0|        if (zip_source_seek(src, args->offset, args->whence) < 0 || (new_position = zip_source_tell(src)) < 0) {
  ------------------
  |  Branch (194:13): [True: 0, False: 0]
  |  Branch (194:69): [True: 0, False: 0]
  ------------------
  195|      0|            zip_error_set_from_source(&ctx->error, src);
  196|      0|            return -1;
  197|      0|        }
  198|       |
  199|      0|        ctx->position = (zip_uint64_t)new_position;
  200|       |
  201|      0|        return 0;
  202|      0|    }
  203|       |
  204|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (204:5): [True: 0, False: 631]
  ------------------
  205|      0|        return (zip_int64_t)ctx->position;
  206|       |
  207|      0|    default:
  ------------------
  |  Branch (207:5): [True: 0, False: 631]
  ------------------
  208|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  209|    631|    }
  210|    631|}
zip_source_crc.c:validate_crc:
  212|    168|zip_int64_t validate_crc(struct crc_context *ctx, zip_source_t *src) {
  213|    168|    struct zip_stat st;
  214|       |
  215|    168|    ctx->size = ctx->position;
  216|       |
  217|    168|    if (ctx->validate) {
  ------------------
  |  Branch (217:9): [True: 168, False: 0]
  ------------------
  218|    168|        if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (218:13): [True: 0, False: 168]
  ------------------
  219|      0|            zip_error_set_from_source(&ctx->error, src);
  220|      0|            return -1;
  221|      0|        }
  222|    168|    }
  223|       |
  224|    168|    if (ctx->crc_position == ctx->position) {
  ------------------
  |  Branch (224:9): [True: 168, False: 0]
  ------------------
  225|    168|        ctx->crc_complete = 1;
  226|       |
  227|    168|        if (ctx->validate) {
  ------------------
  |  Branch (227:13): [True: 168, False: 0]
  ------------------
  228|    168|            if ((st.valid & ZIP_STAT_CRC) && st.crc != ctx->crc) {
  ------------------
  |  |  328|    168|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (228:17): [True: 168, False: 0]
  |  Branch (228:46): [True: 166, False: 2]
  ------------------
  229|    166|                zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
  ------------------
  |  |  138|    166|#define ZIP_ER_CRC 7              /* N CRC error */
  ------------------
  230|    166|                return -1;
  231|    166|            }
  232|    168|        }
  233|    168|    }
  234|       |
  235|      2|    if (ctx->validate) {
  ------------------
  |  Branch (235:9): [True: 2, False: 0]
  ------------------
  236|      2|        if ((st.valid & ZIP_STAT_SIZE) && st.size != ctx->size) {
  ------------------
  |  |  325|      2|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (236:13): [True: 2, False: 0]
  |  Branch (236:43): [True: 0, False: 2]
  ------------------
  237|       |            /* We don't have the index here, but the caller should know which file they are reading from. */
  238|      0|            zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_INVALID_FILE_LENGTH, MAX_DETAIL_INDEX));
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_INVALID_FILE_LENGTH, MAX_DETAIL_INDEX));
  ------------------
  |  |  215|      0|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |  |  Branch (215:48): [Folded, False: 0]
  |  |  ------------------
  ------------------
  239|      0|            return -1;
  240|      0|        }
  241|      2|    }
  242|       |
  243|      2|    return 0;
  244|      2|}

zip_source_error:
   38|  91.7k|zip_error_t *zip_source_error(zip_source_t *src) {
   39|  91.7k|    return &src->error;
   40|  91.7k|}

zip_source_free:
   40|  6.49k|ZIP_EXTERN void zip_source_free(zip_source_t *src) {
   41|  6.49k|    if (src == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 6.49k]
  ------------------
   42|      0|        return;
   43|      0|    }
   44|       |
   45|  6.49k|    if (src->refcount > 0) {
  ------------------
  |  Branch (45:9): [True: 6.49k, False: 0]
  ------------------
   46|  6.49k|        src->refcount--;
   47|  6.49k|    }
   48|  6.49k|    if (src->refcount > 0) {
  ------------------
  |  Branch (48:9): [True: 2.60k, False: 3.88k]
  ------------------
   49|  2.60k|        return;
   50|  2.60k|    }
   51|       |
   52|  3.88k|    if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  3.88k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 84, False: 3.80k]
  |  |  ------------------
  ------------------
   53|     84|        src->open_count = 1; /* force close */
   54|     84|        zip_source_close(src);
   55|     84|    }
   56|  3.88k|    if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  442|  3.88k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  |  |  ------------------
  |  |  |  Branch (442:41): [True: 0, False: 3.88k]
  |  |  ------------------
  ------------------
   57|      0|        zip_source_rollback_write(src);
   58|      0|    }
   59|       |
   60|  3.88k|    if (src->source_archive && !src->source_closed) {
  ------------------
  |  Branch (60:9): [True: 0, False: 3.88k]
  |  Branch (60:32): [True: 0, False: 0]
  ------------------
   61|      0|        _zip_deregister_source(src->source_archive, src);
   62|      0|    }
   63|       |
   64|  3.88k|    (void)_zip_source_call(src, NULL, 0, ZIP_SOURCE_FREE);
   65|       |
   66|  3.88k|    if (src->src) {
  ------------------
  |  Branch (66:9): [True: 168, False: 3.72k]
  ------------------
   67|    168|        zip_source_free(src->src);
   68|    168|    }
   69|       |
   70|  3.88k|    free(src);
   71|  3.88k|}

zip_source_function_create:
   49|  3.72k|ZIP_EXTERN zip_source_t *zip_source_function_create(zip_source_callback zcb, void *ud, zip_error_t *error) {
   50|  3.72k|    zip_source_t *zs;
   51|       |
   52|  3.72k|    if ((zs = _zip_source_new(error)) == NULL) {
  ------------------
  |  Branch (52:9): [True: 0, False: 3.72k]
  ------------------
   53|      0|        return NULL;
   54|      0|    }
   55|       |
   56|  3.72k|    zs->cb.f = zcb;
   57|  3.72k|    zs->ud = ud;
   58|       |
   59|  3.72k|    zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS);
   60|  3.72k|    if (zs->supports < 0) {
  ------------------
  |  Branch (60:9): [True: 0, False: 3.72k]
  ------------------
   61|      0|        zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
  ------------------
  |  |  282|      0|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  283|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  284|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  285|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  286|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  287|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
   62|      0|    }
   63|  3.72k|    zs->supports |= zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, -1);
   64|       |
   65|  3.72k|    return zs;
   66|  3.72k|}
zip_source_keep:
   69|  2.60k|ZIP_EXTERN void zip_source_keep(zip_source_t *src) {
   70|  2.60k|    src->refcount++;
   71|  2.60k|}
_zip_source_new:
   74|  3.88k|zip_source_t *_zip_source_new(zip_error_t *error) {
   75|  3.88k|    zip_source_t *src;
   76|       |
   77|  3.88k|    if ((src = (zip_source_t *)malloc(sizeof(*src))) == NULL) {
  ------------------
  |  Branch (77:9): [True: 0, False: 3.88k]
  ------------------
   78|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   79|      0|        return NULL;
   80|      0|    }
   81|       |
   82|  3.88k|    src->src = NULL;
   83|  3.88k|    src->cb.f = NULL;
   84|  3.88k|    src->ud = NULL;
   85|  3.88k|    src->open_count = 0;
   86|  3.88k|    src->write_state = ZIP_SOURCE_WRITE_CLOSED;
   87|  3.88k|    src->source_closed = false;
   88|  3.88k|    src->source_archive = NULL;
   89|  3.88k|    src->refcount = 1;
   90|  3.88k|    zip_error_init(&src->error);
   91|  3.88k|    src->eof = false;
   92|  3.88k|    src->had_read_error = false;
   93|  3.88k|    src->bytes_read = 0;
   94|  3.88k|    src->have_next_byte = false;
   95|       |
   96|  3.88k|    return src;
   97|  3.88k|}

zip_file_attributes_init:
   36|  3.80k|ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *attributes) {
   37|  3.80k|    attributes->valid = 0;
   38|  3.80k|    attributes->version = 1;
   39|  3.80k|}

zip_source_layered_create:
   49|    168|zip_source_t *zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error) {
   50|    168|    zip_source_t *zs;
   51|    168|    zip_int64_t lower_supports, supports;
   52|       |
   53|    168|    lower_supports = zip_source_supports(src);
   54|    168|    supports = cb(src, ud, &lower_supports, sizeof(lower_supports), ZIP_SOURCE_SUPPORTS);
   55|    168|    if (supports < 0) {
  ------------------
  |  Branch (55:9): [True: 0, False: 168]
  ------------------
   56|      0|        zip_error_set(error, ZIP_ER_INVAL, 0); /* Initialize in case cb doesn't return valid error. */
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   57|      0|        cb(src, ud, error, sizeof(*error), ZIP_SOURCE_ERROR);
   58|      0|        return NULL;
   59|      0|    }
   60|       |
   61|    168|    if ((zs = _zip_source_new(error)) == NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 168]
  ------------------
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|    168|    zs->src = src;
   66|    168|    zs->cb.l = cb;
   67|    168|    zs->ud = ud;
   68|    168|    zs->supports = supports;
   69|       |
   70|       |    /* Layered sources can't support writing, since we currently have no use case. If we want to revisit this, we have to define how the two sources interact. */
   71|    168|    zs->supports &= ~(ZIP_SOURCE_SUPPORTS_WRITABLE & ~ZIP_SOURCE_SUPPORTS_SEEKABLE);
  ------------------
  |  |  294|    168|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  289|    168|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  282|    168|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  287|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  290|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  292|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  295|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  301|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  zs->supports &= ~(ZIP_SOURCE_SUPPORTS_WRITABLE & ~ZIP_SOURCE_SUPPORTS_SEEKABLE);
  ------------------
  |  |  289|    168|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|    168|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|    168|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|    168|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
   72|       |
   73|    168|    return zs;
   74|    168|}

zip_source_open:
   37|  3.97k|ZIP_EXTERN int zip_source_open(zip_source_t *src) {
   38|  3.97k|    if (src->source_closed) {
  ------------------
  |  Branch (38:9): [True: 0, False: 3.97k]
  ------------------
   39|      0|        return -1;
   40|      0|    }
   41|  3.97k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (41:9): [True: 0, False: 3.97k]
  ------------------
   42|      0|        zip_error_set(&src->error, ZIP_ER_DELETED, 0);
  ------------------
  |  |  154|      0|#define ZIP_ER_DELETED 23         /* N Entry has been deleted */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  3.97k|    if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  3.97k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 84, False: 3.88k]
  |  |  ------------------
  ------------------
   47|     84|        if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) == 0) {
  ------------------
  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (47:13): [True: 0, False: 84]
  ------------------
   48|      0|            zip_error_set(&src->error, ZIP_ER_INUSE, 0);
  ------------------
  |  |  160|      0|#define ZIP_ER_INUSE 29           /* N Resource still in use */
  ------------------
   49|      0|            return -1;
   50|      0|        }
   51|     84|    }
   52|  3.88k|    else {
   53|  3.88k|        if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|  3.88k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 168, False: 3.72k]
  |  |  ------------------
  ------------------
   54|    168|            if (zip_source_open(src->src) < 0) {
  ------------------
  |  Branch (54:17): [True: 0, False: 168]
  ------------------
   55|      0|                zip_error_set_from_source(&src->error, src->src);
   56|      0|                return -1;
   57|      0|            }
   58|    168|        }
   59|       |
   60|  3.88k|        if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_OPEN) < 0) {
  ------------------
  |  Branch (60:13): [True: 0, False: 3.88k]
  ------------------
   61|      0|            if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|      0|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   62|      0|                zip_source_close(src->src);
   63|      0|            }
   64|      0|            return -1;
   65|      0|        }
   66|  3.88k|    }
   67|       |
   68|       |    /* TODO: Move the next four lines to into the else branch above, or better yet to zip_source_close()?
   69|       |       They should probably only happen when ZIP_SOURCE_IS_OPEN_READING(src) changes, so other references that have the source open are not affected. */
   70|  3.97k|    src->eof = false;
   71|  3.97k|    src->had_read_error = false;
   72|  3.97k|    _zip_error_clear(&src->error);
   73|  3.97k|    src->bytes_read = 0;
   74|       |
   75|  3.97k|    src->open_count++;
   76|       |
   77|  3.97k|    return 0;
   78|  3.97k|}

zip_source_read:
   38|   198k|zip_int64_t zip_source_read(zip_source_t *src, void *data, zip_uint64_t len) {
   39|   198k|    zip_uint64_t bytes_read;
   40|   198k|    zip_int64_t n;
   41|       |
   42|   198k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 198k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|   198k|    if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
  ------------------
  |  |  441|   396k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
                  if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
  ------------------
  |  |   45|   396k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (45:9): [True: 0, False: 198k]
  |  Branch (45:45): [True: 0, False: 198k]
  |  Branch (45:69): [True: 197k, False: 559]
  |  Branch (45:80): [True: 0, False: 197k]
  ------------------
   46|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|   198k|    if (src->had_read_error) {
  ------------------
  |  Branch (50:9): [True: 19, False: 198k]
  ------------------
   51|     19|        return -1;
   52|     19|    }
   53|       |
   54|   198k|    if (_zip_source_eof(src)) {
  ------------------
  |  Branch (54:9): [True: 19, False: 198k]
  ------------------
   55|     19|        return 0;
   56|     19|    }
   57|       |
   58|   198k|    if (len == 0) {
  ------------------
  |  Branch (58:9): [True: 559, False: 197k]
  ------------------
   59|    559|        return 0;
   60|    559|    }
   61|       |
   62|   197k|    bytes_read = 0;
   63|   197k|    if (src->have_next_byte) {
  ------------------
  |  Branch (63:9): [True: 0, False: 197k]
  ------------------
   64|      0|        ((zip_uint8_t *)data)[0] = src->next_byte;
   65|      0|        bytes_read = 1;
   66|      0|        src->have_next_byte = false;
   67|      0|    }
   68|   395k|    while (bytes_read < len) {
  ------------------
  |  Branch (68:12): [True: 206k, False: 188k]
  ------------------
   69|   206k|        if ((n = _zip_source_call(src, (zip_uint8_t *)data + bytes_read, len - bytes_read, ZIP_SOURCE_READ)) < 0) {
  ------------------
  |  Branch (69:13): [True: 83, False: 206k]
  ------------------
   70|     83|            src->had_read_error = true;
   71|     83|            if (bytes_read == 0) {
  ------------------
  |  Branch (71:17): [True: 64, False: 19]
  ------------------
   72|     64|                return -1;
   73|     64|            }
   74|     19|            else {
   75|     19|                return (zip_int64_t)bytes_read;
   76|     19|            }
   77|     83|        }
   78|       |
   79|   206k|        if (n == 0) {
  ------------------
  |  Branch (79:13): [True: 9.38k, False: 197k]
  ------------------
   80|  9.38k|            src->eof = 1;
   81|  9.38k|            break;
   82|  9.38k|        }
   83|       |
   84|   197k|        bytes_read += (zip_uint64_t)n;
   85|   197k|    }
   86|       |
   87|   197k|    if (src->bytes_read + bytes_read < src->bytes_read) {
  ------------------
  |  Branch (87:9): [True: 0, False: 197k]
  ------------------
   88|      0|        src->bytes_read = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   89|      0|    }
   90|   197k|    else {
   91|   197k|        src->bytes_read += bytes_read;
   92|   197k|    }
   93|   197k|    return (zip_int64_t)bytes_read;
   94|   197k|}
_zip_source_eof:
   97|   198k|bool _zip_source_eof(zip_source_t *src) {
   98|   198k|    return src->eof;
   99|   198k|}

zip_source_seek:
   39|   178k|ZIP_EXTERN int zip_source_seek(zip_source_t *src, zip_int64_t offset, int whence) {
   40|   178k|    zip_source_args_seek_t args;
   41|       |
   42|   178k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 178k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|   178k|    if (!ZIP_SOURCE_IS_OPEN_READING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
  ------------------
  |  |  441|   356k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (45:9): [True: 0, False: 178k]
  |  Branch (45:46): [True: 42.1k, False: 135k]
  |  Branch (45:68): [True: 3.67k, False: 38.4k]
  |  Branch (45:90): [True: 0, False: 3.67k]
  ------------------
   46|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|   178k|    args.offset = offset;
   51|   178k|    args.whence = whence;
   52|       |
   53|   178k|    if (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK) < 0) {
  ------------------
  |  Branch (53:9): [True: 91.7k, False: 86.3k]
  ------------------
   54|  91.7k|        return -1;
   55|  91.7k|    }
   56|       |
   57|       |    /* have_next_byte is never true for sources that support seek. */
   58|  86.3k|    src->eof = 0;
   59|  86.3k|    return 0;
   60|   178k|}
zip_source_seek_compute_offset:
   63|   178k|zip_int64_t zip_source_seek_compute_offset(zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error) {
   64|   178k|    zip_uint64_t new_offset;
   65|   178k|    zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, data_length, error);
  ------------------
  |  |  312|   178k|#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
  |  |  ------------------
  |  |  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  |  |  ------------------
  |  |  |  Branch (312:54): [True: 0, False: 178k]
  |  |  ------------------
  ------------------
   66|       |
   67|   178k|    if (args == NULL) {
  ------------------
  |  Branch (67:9): [True: 0, False: 178k]
  ------------------
   68|      0|        return -1;
   69|      0|    }
   70|       |
   71|   178k|    switch (args->whence) {
   72|  38.4k|    case SEEK_CUR:
  ------------------
  |  Branch (72:5): [True: 38.4k, False: 139k]
  ------------------
   73|  38.4k|        new_offset = _zip_offset_add(offset, args->offset);
   74|  38.4k|        break;
   75|       |
   76|  3.67k|    case SEEK_END:
  ------------------
  |  Branch (76:5): [True: 3.67k, False: 174k]
  ------------------
   77|  3.67k|        new_offset = _zip_offset_add(length, args->offset);
   78|  3.67k|        break;
   79|       |
   80|   135k|    case SEEK_SET:
  ------------------
  |  Branch (80:5): [True: 135k, False: 42.1k]
  ------------------
   81|   135k|        if (args->offset < 0 || (zip_uint64_t)args->offset > length) {
  ------------------
  |  Branch (81:13): [True: 0, False: 135k]
  |  Branch (81:33): [True: 91.7k, False: 44.1k]
  ------------------
   82|  91.7k|            new_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|  91.7k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   83|  91.7k|        }
   84|  44.1k|        else {
   85|  44.1k|            new_offset = (zip_uint64_t)args->offset;
   86|  44.1k|        }
   87|   135k|        break;
   88|       |
   89|      0|    default:
  ------------------
  |  Branch (89:5): [True: 0, False: 178k]
  ------------------
   90|      0|        new_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   91|   178k|    }
   92|       |
   93|   178k|    if (new_offset == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|   178k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (93:9): [True: 91.7k, False: 86.3k]
  ------------------
   94|  91.7k|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|  91.7k|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   95|  91.7k|        return -1;
   96|  91.7k|    }
   97|       |
   98|  86.3k|    return (zip_int64_t)new_offset;
   99|   178k|}
zip_source_seek.c:_zip_offset_add:
  101|  42.1k|static zip_uint64_t _zip_offset_add(zip_uint64_t offset, zip_int64_t delta) {
  102|  42.1k|    if (delta >= 0) {
  ------------------
  |  Branch (102:9): [True: 38.4k, False: 3.67k]
  ------------------
  103|  38.4k|        zip_uint64_t unsigned_delta = (zip_uint64_t)delta;
  104|       |
  105|  38.4k|        if (offset > ZIP_INT64_MAX - unsigned_delta) {
  ------------------
  |  |   45|  38.4k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (105:13): [True: 0, False: 38.4k]
  ------------------
  106|      0|            return ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  107|      0|        }
  108|  38.4k|        return offset + unsigned_delta;
  109|  38.4k|    }
  110|  3.67k|    else {
  111|       |        /* Handle ZIP_INT64_MIN without overflowing signed arithmetic. */
  112|  3.67k|        zip_uint64_t unsigned_delta = (zip_uint64_t)(-(delta + 1)) + 1;
  113|       |
  114|  3.67k|        if (offset < unsigned_delta) {
  ------------------
  |  Branch (114:13): [True: 0, False: 3.67k]
  ------------------
  115|      0|            return ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  116|      0|        }
  117|  3.67k|        return offset - unsigned_delta;
  118|  3.67k|    }
  119|  42.1k|}

zip_source_stat:
   38|  7.77k|ZIP_EXTERN int zip_source_stat(zip_source_t *src, zip_stat_t *st) {
   39|  7.77k|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 7.77k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|  7.77k|    if (st == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 7.77k]
  ------------------
   43|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|  7.77k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (47:9): [True: 0, False: 7.77k]
  ------------------
   48|      0|        zip_error_set(&src->error, ZIP_ER_READ, ENOENT);
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
   49|      0|    }
   50|       |
   51|  7.77k|    zip_stat_init(st);
   52|       |
   53|  7.77k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|  7.77k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 168, False: 7.61k]
  |  |  ------------------
  ------------------
   54|    168|        if (zip_source_stat(src->src, st) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 168]
  ------------------
   55|      0|            zip_error_set_from_source(&src->error, src->src);
   56|      0|            return -1;
   57|      0|        }
   58|    168|    }
   59|       |
   60|  7.77k|    if (_zip_source_call(src, st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
  ------------------
  |  Branch (60:9): [True: 0, False: 7.77k]
  ------------------
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|  7.77k|    return 0;
   65|  7.77k|}

zip_source_supports:
   40|  4.14k|zip_int64_t zip_source_supports(zip_source_t *src) {
   41|  4.14k|    return src->supports;
   42|  4.14k|}
zip_source_make_command_bitmap:
   48|  7.69k|ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t cmd0, ...) {
   49|  7.69k|    zip_int64_t bitmap;
   50|  7.69k|    va_list ap;
   51|       |
   52|  7.69k|    bitmap = ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd0);
  ------------------
  |  |  276|  7.69k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
   53|       |
   54|       |
   55|  7.69k|    va_start(ap, cmd0);
   56|  75.5k|    for (;;) {
   57|  75.5k|        int cmd = va_arg(ap, int);
   58|  75.5k|        if (cmd < 0) {
  ------------------
  |  Branch (58:13): [True: 7.69k, False: 67.8k]
  ------------------
   59|  7.69k|            break;
   60|  7.69k|        }
   61|  67.8k|        bitmap |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd);
  ------------------
  |  |  276|  67.8k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
   62|  67.8k|    }
   63|  7.69k|    va_end(ap);
   64|       |
   65|  7.69k|    return bitmap;
   66|  7.69k|}

zip_source_tell:
   38|  3.84k|ZIP_EXTERN zip_int64_t zip_source_tell(zip_source_t *src) {
   39|  3.84k|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 3.84k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|  3.84k|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  3.84k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (42:9): [True: 0, False: 3.84k]
  ------------------
   43|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|  3.84k|    if ((src->supports & (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK))) == 0) {
  ------------------
  |  |  276|  3.84k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
                  if ((src->supports & (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK))) == 0) {
  ------------------
  |  |  276|  3.84k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (47:9): [True: 0, False: 3.84k]
  ------------------
   48|      0|        if (src->bytes_read > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (48:13): [True: 0, False: 0]
  ------------------
   49|      0|            zip_error_set(&src->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
   50|      0|            return -1;
   51|      0|        }
   52|      0|        return (zip_int64_t)src->bytes_read;
   53|      0|    }
   54|       |
   55|  3.84k|    return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL);
   56|  3.84k|}

_zip_source_window_new:
   68|     84|zip_source_t *_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_int64_t length, zip_stat_t *st, zip_uint64_t st_invalid, zip_file_attributes_t *attributes, zip_dostime_t *dostime, zip_t *source_archive, zip_uint64_t source_index, bool take_ownership, zip_error_t *error) {
   69|     84|    zip_source_t *window_source;
   70|     84|    struct window *ctx;
   71|       |
   72|     84|    if (src == NULL || length < -1 || (source_archive == NULL && source_index != 0)) {
  ------------------
  |  Branch (72:9): [True: 0, False: 84]
  |  Branch (72:24): [True: 0, False: 84]
  |  Branch (72:40): [True: 84, False: 0]
  |  Branch (72:66): [True: 0, False: 84]
  ------------------
   73|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   74|      0|        return NULL;
   75|      0|    }
   76|       |
   77|     84|    if (length >= 0) {
  ------------------
  |  Branch (77:9): [True: 84, False: 0]
  ------------------
   78|     84|        if (start + (zip_uint64_t)length < start) {
  ------------------
  |  Branch (78:13): [True: 0, False: 84]
  ------------------
   79|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   80|      0|            return NULL;
   81|      0|        }
   82|     84|    }
   83|       |
   84|     84|    if ((ctx = (struct window *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (84:9): [True: 0, False: 84]
  ------------------
   85|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   86|      0|        return NULL;
   87|      0|    }
   88|       |
   89|     84|    ctx->start = start;
   90|     84|    if (length == -1) {
  ------------------
  |  Branch (90:9): [True: 0, False: 84]
  ------------------
   91|      0|        ctx->end_valid = false;
   92|      0|    }
   93|     84|    else {
   94|     84|        ctx->end = start + (zip_uint64_t)length;
   95|     84|        ctx->end_valid = true;
   96|     84|    }
   97|     84|    zip_stat_init(&ctx->stat);
   98|     84|    ctx->stat_invalid = st_invalid;
   99|     84|    if (attributes != NULL) {
  ------------------
  |  Branch (99:9): [True: 0, False: 84]
  ------------------
  100|      0|        (void)memcpy_s(&ctx->attributes, sizeof(ctx->attributes), attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  101|      0|    }
  102|     84|    else {
  103|     84|        zip_file_attributes_init(&ctx->attributes);
  104|     84|    }
  105|     84|    if (dostime != NULL) {
  ------------------
  |  Branch (105:9): [True: 0, False: 84]
  ------------------
  106|      0|        ctx->dostime = *dostime;
  107|      0|        ctx->dostime_valid = true;
  108|      0|    }
  109|     84|    else {
  110|     84|        ctx->dostime_valid = false;
  111|     84|    }
  112|     84|    ctx->source_archive = source_archive;
  113|     84|    ctx->source_index = source_index;
  114|     84|    zip_error_init(&ctx->error);
  115|     84|    ctx->supports = (zip_source_supports(src) & (ZIP_SOURCE_SUPPORTS_SEEKABLE | ZIP_SOURCE_SUPPORTS_REOPEN)) | (zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_GET_DOS_TIME, ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, ZIP_SOURCE_FREE, -1));
  ------------------
  |  |  289|     84|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|     84|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|     84|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  116|     84|    if (ctx->end_valid) {
  ------------------
  |  Branch (116:9): [True: 84, False: 0]
  ------------------
  117|     84|        ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_AT_EOF);
  ------------------
  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  118|     84|    }
  119|     84|    ctx->needs_seek = (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) ? true : false;
  ------------------
  |  |  276|     84|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (119:23): [True: 84, False: 0]
  ------------------
  120|       |
  121|     84|    if (st) {
  ------------------
  |  Branch (121:9): [True: 84, False: 0]
  ------------------
  122|     84|        if (_zip_stat_merge(&ctx->stat, st, error) < 0) {
  ------------------
  |  Branch (122:13): [True: 0, False: 84]
  ------------------
  123|      0|            free(ctx);
  124|      0|            return NULL;
  125|      0|        }
  126|     84|    }
  127|       |
  128|     84|    window_source = zip_source_layered_create(src, window_read, ctx, error);
  129|     84|    if (window_source == NULL) {
  ------------------
  |  Branch (129:9): [True: 0, False: 84]
  ------------------
  130|      0|        free(ctx);
  131|      0|        return NULL;
  132|      0|    }
  133|     84|    if (!take_ownership) {
  ------------------
  |  Branch (133:9): [True: 84, False: 0]
  ------------------
  134|     84|        zip_source_keep(src);
  135|     84|    }
  136|     84|    return window_source;
  137|     84|}
zip_source_window.c:window_read:
  156|    633|static zip_int64_t window_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  157|    633|    struct window *ctx;
  158|    633|    zip_int64_t ret;
  159|    633|    zip_uint64_t n, i;
  160|       |
  161|    633|    ctx = (struct window *)_ctx;
  162|       |
  163|    633|    switch (cmd) {
  164|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (164:5): [True: 0, False: 633]
  ------------------
  165|      0|        if (ctx->end_valid) {
  ------------------
  |  Branch (165:13): [True: 0, False: 0]
  ------------------
  166|      0|            return ctx->offset == ctx->end;
  167|      0|        }
  168|      0|        else {
  169|      0|            return zip_source_pass_to_lower_layer(src, data, len, cmd);
  170|      0|        }
  171|       |
  172|     84|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (172:5): [True: 84, False: 549]
  ------------------
  173|     84|        return 0;
  174|       |
  175|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (175:5): [True: 0, False: 633]
  ------------------
  176|      0|        return zip_error_to_data(&ctx->error, data, len);
  177|       |
  178|     84|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (178:5): [True: 84, False: 549]
  ------------------
  179|     84|        free(ctx);
  180|     84|        return 0;
  181|       |
  182|     84|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (182:5): [True: 84, False: 549]
  ------------------
  183|     84|        if (ctx->source_archive) {
  ------------------
  |  Branch (183:13): [True: 0, False: 84]
  ------------------
  184|      0|            zip_uint64_t offset;
  185|       |
  186|      0|            if ((offset = _zip_file_get_offset(ctx->source_archive, ctx->source_index, &ctx->error)) == 0) {
  ------------------
  |  Branch (186:17): [True: 0, False: 0]
  ------------------
  187|      0|                return -1;
  188|      0|            }
  189|      0|            if (ctx->end_valid) {
  ------------------
  |  Branch (189:17): [True: 0, False: 0]
  ------------------
  190|      0|                if (ctx->end + offset < ctx->end) {
  ------------------
  |  Branch (190:21): [True: 0, False: 0]
  ------------------
  191|       |                    /* zip archive data claims end of data past zip64 limits */
  192|      0|                    zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, ctx->source_index));
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                                  zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, ctx->source_index));
  ------------------
  |  |  215|      0|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |  |  Branch (215:48): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  193|      0|                    return -1;
  194|      0|                }
  195|      0|                ctx->end += offset;
  196|      0|            }
  197|      0|            ctx->start += offset;
  198|      0|            ctx->source_archive = NULL;
  199|      0|        }
  200|       |
  201|     84|        if (!ctx->needs_seek) {
  ------------------
  |  Branch (201:13): [True: 0, False: 84]
  ------------------
  202|      0|            DEFINE_BYTE_ARRAY(b, BUFSIZE);
  ------------------
  |  |  477|      0|#define DEFINE_BYTE_ARRAY(buf, size) zip_uint8_t buf[size]
  ------------------
  203|       |
  204|      0|            if (!byte_array_init(b, BUFSIZE)) {
  ------------------
  |  |  478|      0|#define byte_array_init(buf, size) (1)
  ------------------
  |  Branch (204:17): [Folded, False: 0]
  ------------------
  205|      0|                zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  206|      0|                return -1;
  207|      0|            }
  208|       |
  209|      0|            for (n = 0; n < ctx->start; n += (zip_uint64_t)ret) {
  ------------------
  |  Branch (209:25): [True: 0, False: 0]
  ------------------
  210|      0|                i = (ctx->start - n > BUFSIZE ? BUFSIZE : ctx->start - n);
  ------------------
  |  |   66|      0|#define BUFSIZE 8192
  ------------------
                              i = (ctx->start - n > BUFSIZE ? BUFSIZE : ctx->start - n);
  ------------------
  |  |   66|      0|#define BUFSIZE 8192
  ------------------
  |  Branch (210:22): [True: 0, False: 0]
  ------------------
  211|      0|                if ((ret = zip_source_read(src, b, i)) < 0) {
  ------------------
  |  Branch (211:21): [True: 0, False: 0]
  ------------------
  212|      0|                    zip_error_set_from_source(&ctx->error, src);
  213|      0|                    byte_array_fini(b);
  ------------------
  |  |  479|      0|#define byte_array_fini(buf) ((void)0)
  ------------------
  214|      0|                    return -1;
  215|      0|                }
  216|      0|                if (ret == 0) {
  ------------------
  |  Branch (216:21): [True: 0, False: 0]
  ------------------
  217|      0|                    zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  218|      0|                    byte_array_fini(b);
  ------------------
  |  |  479|      0|#define byte_array_fini(buf) ((void)0)
  ------------------
  219|      0|                    return -1;
  220|      0|                }
  221|      0|            }
  222|       |
  223|      0|            byte_array_fini(b);
  ------------------
  |  |  479|      0|#define byte_array_fini(buf) ((void)0)
  ------------------
  224|      0|        }
  225|       |
  226|     84|        ctx->offset = ctx->start;
  227|     84|        return 0;
  228|       |
  229|    129|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (229:5): [True: 129, False: 504]
  ------------------
  230|    129|        if (ctx->end_valid && len > ctx->end - ctx->offset) {
  ------------------
  |  Branch (230:13): [True: 129, False: 0]
  |  Branch (230:31): [True: 103, False: 26]
  ------------------
  231|    103|            len = ctx->end - ctx->offset;
  232|    103|        }
  233|       |
  234|    129|        if (len == 0) {
  ------------------
  |  Branch (234:13): [True: 84, False: 45]
  ------------------
  235|     84|            return 0;
  236|     84|        }
  237|       |
  238|     45|        if (ctx->needs_seek) {
  ------------------
  |  Branch (238:13): [True: 45, False: 0]
  ------------------
  239|     45|            if (zip_source_seek(src, (zip_int64_t)ctx->offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (239:17): [True: 0, False: 45]
  ------------------
  240|      0|                zip_error_set_from_source(&ctx->error, src);
  241|      0|                return -1;
  242|      0|            }
  243|     45|        }
  244|       |
  245|     45|        if ((ret = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (245:13): [True: 0, False: 45]
  ------------------
  246|      0|            zip_error_set_from_source(&ctx->error, src);
  247|      0|            return -1;
  248|      0|        }
  249|       |
  250|     45|        if (ret == 0) {
  ------------------
  |  Branch (250:13): [True: 0, False: 45]
  ------------------
  251|      0|            if (ctx->end_valid && ctx->offset < ctx->end) {
  ------------------
  |  Branch (251:17): [True: 0, False: 0]
  |  Branch (251:35): [True: 0, False: 0]
  ------------------
  252|      0|                zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  253|      0|                return -1;
  254|      0|            }
  255|      0|        }
  256|       |
  257|     45|        ctx->offset += (zip_uint64_t)ret;
  258|     45|        return ret;
  259|       |
  260|      0|    case ZIP_SOURCE_SEEK: {
  ------------------
  |  Branch (260:5): [True: 0, False: 633]
  ------------------
  261|      0|        zip_uint64_t length;
  262|      0|        zip_int64_t new_offset;
  263|      0|        zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
  ------------------
  |  |  312|      0|#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
  |  |  ------------------
  |  |  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  |  |  ------------------
  |  |  |  Branch (312:54): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  264|       |
  265|       |        /*
  266|       |          If we don't know the length and seek from the end, we seek in the lower source to get the new offset.
  267|       |        */
  268|      0|        if (!ctx->end_valid && args->whence == SEEK_END) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  |  Branch (268:32): [True: 0, False: 0]
  ------------------
  269|      0|            zip_int64_t lower_offset;
  270|       |
  271|      0|            if (zip_source_seek(src, args->offset, args->whence) < 0) {
  ------------------
  |  Branch (271:17): [True: 0, False: 0]
  ------------------
  272|      0|                zip_error_set_from_source(&ctx->error, src);
  273|      0|                return -1;
  274|      0|            }
  275|      0|            if ((lower_offset = zip_source_tell(src)) < 0) {
  ------------------
  |  Branch (275:17): [True: 0, False: 0]
  ------------------
  276|      0|                zip_error_set_from_source(&ctx->error, src);
  277|      0|                return -1;
  278|      0|            }
  279|      0|            if ((zip_uint64_t)lower_offset < ctx->start) {
  ------------------
  |  Branch (279:17): [True: 0, False: 0]
  ------------------
  280|      0|                zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  281|      0|                return -1;
  282|      0|            }
  283|      0|            ctx->offset = (zip_uint64_t)lower_offset;
  284|      0|            return 0;
  285|      0|        }
  286|       |
  287|       |        /* 
  288|       |          If we don't know the length, we disable the end check in zip_source_seek_compute_offset by passing in the largest possible value and seek in the lower source to validate the new offset.
  289|       |        */
  290|      0|        length = ctx->end_valid ? (ctx->end - ctx->start) : ZIP_INT64_MAX;
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (290:18): [True: 0, False: 0]
  ------------------
  291|      0|        new_offset = zip_source_seek_compute_offset(ctx->offset - ctx->start, length, data, len, &ctx->error);
  292|       |
  293|      0|        if (new_offset < 0) {
  ------------------
  |  Branch (293:13): [True: 0, False: 0]
  ------------------
  294|      0|            return -1;
  295|      0|        }
  296|       |
  297|      0|        if (new_offset + ctx->start < ctx->start) {
  ------------------
  |  Branch (297:13): [True: 0, False: 0]
  ------------------
  298|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  299|      0|            return -1;
  300|      0|        }
  301|      0|        new_offset += ctx->start;
  302|       |
  303|      0|        if (!ctx->end_valid) {
  ------------------
  |  Branch (303:13): [True: 0, False: 0]
  ------------------
  304|      0|            if (zip_source_seek(src, new_offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (304:17): [True: 0, False: 0]
  ------------------
  305|      0|                zip_error_set_from_source(&ctx->error, src);
  306|      0|                return -1;
  307|      0|            }
  308|      0|        }
  309|      0|        ctx->offset = (zip_uint64_t)new_offset;
  310|      0|        return 0;
  311|      0|    }
  312|       |
  313|    168|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (313:5): [True: 168, False: 465]
  ------------------
  314|    168|        zip_stat_t *st;
  315|       |
  316|    168|        st = (zip_stat_t *)data;
  317|       |
  318|    168|        if (_zip_stat_merge(st, &ctx->stat, &ctx->error) < 0) {
  ------------------
  |  Branch (318:13): [True: 0, False: 168]
  ------------------
  319|      0|            return -1;
  320|      0|        }
  321|       |
  322|    168|        if (!(ctx->stat.valid & ZIP_STAT_SIZE)) {
  ------------------
  |  |  325|    168|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (322:13): [True: 0, False: 168]
  ------------------
  323|      0|            if (ctx->end_valid) {
  ------------------
  |  Branch (323:17): [True: 0, False: 0]
  ------------------
  324|      0|                st->valid |= ZIP_STAT_SIZE;
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  325|      0|                st->size = ctx->end - ctx->start;
  326|      0|            }
  327|      0|            else if (st->valid & ZIP_STAT_SIZE) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (327:22): [True: 0, False: 0]
  ------------------
  328|      0|                st->size -= ctx->start;
  329|      0|            }
  330|      0|        }
  331|       |
  332|    168|        st->valid &= ~ctx->stat_invalid;
  333|       |
  334|    168|        return 0;
  335|    168|    }
  336|       |
  337|      0|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES:
  ------------------
  |  Branch (337:5): [True: 0, False: 633]
  ------------------
  338|      0|        if (len < sizeof(ctx->attributes)) {
  ------------------
  |  Branch (338:13): [True: 0, False: 0]
  ------------------
  339|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  340|      0|            return -1;
  341|      0|        }
  342|       |
  343|      0|        (void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  344|      0|        return sizeof(ctx->attributes);
  345|       |
  346|      0|    case ZIP_SOURCE_GET_DOS_TIME:
  ------------------
  |  Branch (346:5): [True: 0, False: 633]
  ------------------
  347|      0|        if (len < sizeof(ctx->dostime)) {
  ------------------
  |  Branch (347:13): [True: 0, False: 0]
  ------------------
  348|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  349|      0|            return -1;
  350|      0|        }
  351|      0|        if (ctx->dostime_valid) {
  ------------------
  |  Branch (351:13): [True: 0, False: 0]
  ------------------
  352|      0|            (void)memcpy_s(data, sizeof(ctx->dostime), &ctx->dostime, sizeof(ctx->dostime));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  353|      0|            return sizeof(ctx->dostime);
  354|      0|        }
  355|      0|        else {
  356|      0|            return 0;
  357|      0|        }
  358|       |
  359|     84|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (359:5): [True: 84, False: 549]
  ------------------
  360|     84|        return ctx->supports;
  361|       |
  362|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (362:5): [True: 0, False: 633]
  ------------------
  363|      0|        return (zip_int64_t)(ctx->offset - ctx->start);
  364|       |
  365|      0|    default:
  ------------------
  |  Branch (365:5): [True: 0, False: 633]
  ------------------
  366|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  367|    633|    }
  368|    633|}

zip_stat_index:
   38|  23.7k|ZIP_EXTERN int zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st) {
   39|  23.7k|    const char *name;
   40|  23.7k|    zip_dirent_t *de;
   41|  23.7k|    zip_entry_t *entry;
   42|       |
   43|  23.7k|    if ((de = _zip_get_dirent(za, index, flags, NULL)) == NULL) {
  ------------------
  |  Branch (43:9): [True: 0, False: 23.7k]
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|  23.7k|    if ((name = zip_get_name(za, index, flags)) == NULL) {
  ------------------
  |  Branch (47:9): [True: 0, False: 23.7k]
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|  23.7k|    entry = za->entry + index;
   52|       |
   53|  23.7k|    if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
  ------------------
  |  |   98|  23.7k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
                  if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
  ------------------
  |  |  518|  23.7k|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  ------------------
  |  |  |  Branch (518:35): [True: 0, False: 23.7k]
  |  |  ------------------
  ------------------
  |  Branch (53:9): [True: 23.7k, False: 0]
  ------------------
   54|      0|        if (zip_source_stat(entry->source, st) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 0]
  ------------------
   55|      0|            zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
  ------------------
  |  |  146|      0|#define ZIP_ER_CHANGED 15         /* N Entry has been changed */
  ------------------
   56|      0|            return -1;
   57|      0|        }
   58|       |
   59|      0|        if (de->comp_method == ZIP_CM_DEFAULT) {
  ------------------
  |  |  178|      0|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  |  Branch (59:13): [True: 0, False: 0]
  ------------------
   60|      0|            if (!(st->valid & ZIP_STAT_COMP_METHOD) || st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                          if (!(st->valid & ZIP_STAT_COMP_METHOD) || st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (60:17): [True: 0, False: 0]
  |  Branch (60:56): [True: 0, False: 0]
  ------------------
   61|      0|                st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                              st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
   62|      0|            }
   63|      0|        }
   64|      0|        else {
   65|      0|            if ((st->valid & ZIP_STAT_COMP_METHOD) && st->comp_method != de->comp_method) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  |  Branch (65:17): [True: 0, False: 0]
  |  Branch (65:55): [True: 0, False: 0]
  ------------------
   66|      0|                st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
   67|      0|            }
   68|      0|            st->valid |= ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
   69|      0|            st->comp_method = de->comp_method;
   70|      0|        }
   71|       |
   72|      0|        if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (72:13): [True: 0, False: 0]
  |  Branch (72:113): [True: 0, False: 0]
  ------------------
   73|      0|            st->valid |= ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
   74|      0|            st->comp_size = st->size;
   75|      0|        }
   76|       |
   77|      0|        if (entry->changes != NULL && entry->changes->changed & ZIP_DIRENT_LAST_MOD) {
  ------------------
  |  |  341|      0|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (77:13): [True: 0, False: 0]
  |  Branch (77:39): [True: 0, False: 0]
  ------------------
   78|      0|            st->mtime = zip_dirent_get_last_mod_mtime(de);
   79|      0|            st->valid |= ZIP_STAT_MTIME;
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
   80|      0|        }
   81|      0|    }
   82|  23.7k|    else {
   83|  23.7k|        zip_stat_init(st);
   84|       |
   85|  23.7k|        st->crc = de->crc;
   86|  23.7k|        st->size = de->uncomp_size;
   87|  23.7k|        st->mtime = zip_dirent_get_last_mod_mtime(de);
   88|  23.7k|        st->comp_size = de->comp_size;
   89|  23.7k|        st->comp_method = (zip_uint16_t)de->comp_method;
   90|  23.7k|        st->encryption_method = de->encryption_method;
   91|  23.7k|        st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  328|  23.7k|#define ZIP_STAT_CRC 0x0020u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  325|  23.7k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  327|  23.7k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|  23.7k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|  23.7k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  23.7k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  |  Branch (91:22): [True: 23.7k, False: 0]
  ------------------
   92|  23.7k|        if (entry->changes != NULL && entry->changes->changed & ZIP_DIRENT_COMP_METHOD) {
  ------------------
  |  |  336|      0|#define ZIP_DIRENT_COMP_METHOD 0x0001u
  ------------------
  |  Branch (92:13): [True: 0, False: 23.7k]
  |  Branch (92:39): [True: 0, False: 0]
  ------------------
   93|      0|            st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
   94|      0|        }
   95|  23.7k|    }
   96|       |
   97|  23.7k|    if ((za->ch_flags & ZIP_AFL_WANT_TORRENTZIP) && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |  115|  23.7k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  ------------------
                  if ((za->ch_flags & ZIP_AFL_WANT_TORRENTZIP) && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (97:9): [True: 0, False: 23.7k]
  |  Branch (97:53): [True: 0, False: 0]
  ------------------
   98|      0|        if (za->torrent_mtime == 0) {
  ------------------
  |  Branch (98:13): [True: 0, False: 0]
  ------------------
   99|      0|            zip_dostime_t dostime = {0xbc00, 0x2198};
  100|      0|            za->torrent_mtime = _zip_d2u_time(&dostime);
  101|      0|        }
  102|      0|        st->comp_method = ZIP_CM_DEFLATE;
  ------------------
  |  |  187|      0|#define ZIP_CM_DEFLATE 8         /* deflated */
  ------------------
  103|      0|        st->mtime = za->torrent_mtime;
  104|      0|        st->valid |= ZIP_STAT_MTIME | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
                      st->valid |= ZIP_STAT_MTIME | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  105|      0|        st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  106|      0|    }
  107|       |
  108|  23.7k|    st->index = index;
  109|  23.7k|    st->name = name;
  110|  23.7k|    st->valid |= ZIP_STAT_INDEX | ZIP_STAT_NAME;
  ------------------
  |  |  324|  23.7k|#define ZIP_STAT_INDEX 0x0002u
  ------------------
                  st->valid |= ZIP_STAT_INDEX | ZIP_STAT_NAME;
  ------------------
  |  |  323|  23.7k|#define ZIP_STAT_NAME 0x0001u
  ------------------
  111|       |
  112|  23.7k|    return 0;
  113|  23.7k|}

zip_stat_init:
   39|  70.4k|ZIP_EXTERN void zip_stat_init(zip_stat_t *st) {
   40|  70.4k|    st->valid = 0;
   41|  70.4k|    st->name = NULL;
   42|  70.4k|    st->index = ZIP_UINT64_MAX;
  ------------------
  |  |   46|  70.4k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   43|  70.4k|    st->crc = 0;
   44|  70.4k|    st->mtime = (time_t)-1;
   45|  70.4k|    st->size = 0;
   46|  70.4k|    st->comp_size = 0;
   47|  70.4k|    st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|  70.4k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
   48|  70.4k|    st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  70.4k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
   49|  70.4k|}
_zip_stat_merge:
   52|    252|int _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error) {
   53|       |    /* name is not merged, since zip_stat_t doesn't own it, and src may not be valid as long as dst */
   54|    252|    if (src->valid & ZIP_STAT_INDEX) {
  ------------------
  |  |  324|    252|#define ZIP_STAT_INDEX 0x0002u
  ------------------
  |  Branch (54:9): [True: 0, False: 252]
  ------------------
   55|      0|        dst->index = src->index;
   56|      0|    }
   57|    252|    if (src->valid & ZIP_STAT_SIZE) {
  ------------------
  |  |  325|    252|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (57:9): [True: 252, False: 0]
  ------------------
   58|    252|        dst->size = src->size;
   59|    252|    }
   60|    252|    if (src->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  326|    252|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (60:9): [True: 0, False: 252]
  ------------------
   61|      0|        dst->comp_size = src->comp_size;
   62|      0|    }
   63|    252|    if (src->valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  327|    252|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (63:9): [True: 0, False: 252]
  ------------------
   64|      0|        dst->mtime = src->mtime;
   65|      0|    }
   66|    252|    if (src->valid & ZIP_STAT_CRC) {
  ------------------
  |  |  328|    252|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (66:9): [True: 252, False: 0]
  ------------------
   67|    252|        dst->crc = src->crc;
   68|    252|    }
   69|    252|    if (src->valid & ZIP_STAT_COMP_METHOD) {
  ------------------
  |  |  329|    252|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  |  Branch (69:9): [True: 0, False: 252]
  ------------------
   70|      0|        dst->comp_method = src->comp_method;
   71|      0|    }
   72|    252|    if (src->valid & ZIP_STAT_ENCRYPTION_METHOD) {
  ------------------
  |  |  330|    252|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  |  Branch (72:9): [True: 0, False: 252]
  ------------------
   73|      0|        dst->encryption_method = src->encryption_method;
   74|      0|    }
   75|    252|    if (src->valid & ZIP_STAT_FLAGS) {
  ------------------
  |  |  331|    252|#define ZIP_STAT_FLAGS 0x0100u
  ------------------
  |  Branch (75:9): [True: 0, False: 252]
  ------------------
   76|      0|        dst->flags = src->flags;
   77|      0|    }
   78|    252|    dst->valid |= src->valid;
   79|       |
   80|    252|    return 0;
   81|    252|}

_zip_string_crc32:
   41|  2.79k|zip_uint32_t _zip_string_crc32(const zip_string_t *s) {
   42|  2.79k|    zip_uint32_t crc;
   43|       |
   44|  2.79k|    crc = (zip_uint32_t)crc32(0L, Z_NULL, 0);
   45|       |
   46|  2.79k|    if (s != NULL) {
  ------------------
  |  Branch (46:9): [True: 406, False: 2.39k]
  ------------------
   47|    406|        crc = (zip_uint32_t)crc32(crc, s->raw, s->length);
   48|    406|    }
   49|       |
   50|  2.79k|    return crc;
   51|  2.79k|}
_zip_string_free:
   69|   180k|void _zip_string_free(zip_string_t *s) {
   70|   180k|    if (s == NULL) {
  ------------------
  |  Branch (70:9): [True: 107k, False: 73.1k]
  ------------------
   71|   107k|        return;
   72|   107k|    }
   73|       |
   74|  73.1k|    free(s->raw);
   75|  73.1k|    free(s->converted);
   76|  73.1k|    free(s);
   77|  73.1k|}
_zip_string_get:
   80|  72.4k|const zip_uint8_t *_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error) {
   81|  72.4k|    static const zip_uint8_t empty[1] = "";
   82|       |
   83|  72.4k|    if (string == NULL) {
  ------------------
  |  Branch (83:9): [True: 25.4k, False: 46.9k]
  ------------------
   84|  25.4k|        if (lenp) {
  ------------------
  |  Branch (84:13): [True: 23.4k, False: 2.07k]
  ------------------
   85|  23.4k|            *lenp = 0;
   86|  23.4k|        }
   87|  25.4k|        return empty;
   88|  25.4k|    }
   89|       |
   90|  46.9k|    if ((flags & ZIP_FL_ENC_RAW) == 0) {
  ------------------
  |  |  102|  46.9k|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
  |  Branch (90:9): [True: 46.9k, False: 0]
  ------------------
   91|       |        /* start guessing */
   92|  46.9k|        if (string->encoding == ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (92:13): [True: 23.7k, False: 23.1k]
  ------------------
   93|       |            /* guess encoding, sets string->encoding */
   94|  23.7k|            (void)_zip_guess_encoding(string, ZIP_ENCODING_UNKNOWN);
   95|  23.7k|        }
   96|       |
   97|  46.9k|        if (((flags & ZIP_FL_ENC_STRICT) && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN) || (string->encoding == ZIP_ENCODING_CP437)) {
  ------------------
  |  |  103|  46.9k|#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
  ------------------
  |  Branch (97:14): [True: 0, False: 46.9k]
  |  Branch (97:45): [True: 0, False: 0]
  |  Branch (97:87): [True: 0, False: 0]
  |  Branch (97:135): [True: 4.79k, False: 42.1k]
  ------------------
   98|  4.79k|            if (string->converted == NULL) {
  ------------------
  |  Branch (98:17): [True: 2.84k, False: 1.94k]
  ------------------
   99|  2.84k|                if ((string->converted = _zip_cp437_to_utf8(string->raw, string->length, &string->converted_length, error)) == NULL) {
  ------------------
  |  Branch (99:21): [True: 0, False: 2.84k]
  ------------------
  100|      0|                    return NULL;
  101|      0|                }
  102|  2.84k|            }
  103|  4.79k|            if (lenp) {
  ------------------
  |  Branch (103:17): [True: 904, False: 3.89k]
  ------------------
  104|    904|                *lenp = string->converted_length;
  105|    904|            }
  106|  4.79k|            return string->converted;
  107|  4.79k|        }
  108|  46.9k|    }
  109|       |
  110|  42.1k|    if (lenp) {
  ------------------
  |  Branch (110:9): [True: 624, False: 41.5k]
  ------------------
  111|    624|        *lenp = string->length;
  112|    624|    }
  113|  42.1k|    return string->raw;
  114|  46.9k|}
_zip_string_length:
  131|  1.20k|zip_uint16_t _zip_string_length(const zip_string_t *s) {
  132|  1.20k|    if (s == NULL) {
  ------------------
  |  Branch (132:9): [True: 543, False: 660]
  ------------------
  133|    543|        return 0;
  134|    543|    }
  135|       |
  136|    660|    return s->length;
  137|  1.20k|}
_zip_string_new:
  140|  73.6k|zip_string_t *_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error) {
  141|  73.6k|    zip_string_t *s;
  142|  73.6k|    zip_encoding_type_t expected_encoding;
  143|       |
  144|  73.6k|    if (length == 0) {
  ------------------
  |  Branch (144:9): [True: 453, False: 73.1k]
  ------------------
  145|    453|        return NULL;
  146|    453|    }
  147|       |
  148|  73.1k|    switch (flags & ZIP_FL_ENCODING_ALL) {
  ------------------
  |  |  266|  73.1k|#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  101|  73.1k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  108|  73.1k|#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  107|  73.1k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  |  |  ------------------
  ------------------
  149|  71.1k|    case ZIP_FL_ENC_GUESS:
  ------------------
  |  |  101|  71.1k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (149:5): [True: 71.1k, False: 2.02k]
  ------------------
  150|  71.1k|        expected_encoding = ZIP_ENCODING_UNKNOWN;
  151|  71.1k|        break;
  152|  2.02k|    case ZIP_FL_ENC_UTF_8:
  ------------------
  |  |  107|  2.02k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
  |  Branch (152:5): [True: 2.02k, False: 71.1k]
  ------------------
  153|  2.02k|        expected_encoding = ZIP_ENCODING_UTF8_KNOWN;
  154|  2.02k|        break;
  155|      0|    case ZIP_FL_ENC_CP437:
  ------------------
  |  |  108|      0|#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
  ------------------
  |  Branch (155:5): [True: 0, False: 73.1k]
  ------------------
  156|      0|        expected_encoding = ZIP_ENCODING_CP437;
  157|      0|        break;
  158|      0|    default:
  ------------------
  |  Branch (158:5): [True: 0, False: 73.1k]
  ------------------
  159|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  160|      0|        return NULL;
  161|  73.1k|    }
  162|       |
  163|  73.1k|    if ((s = (zip_string_t *)malloc(sizeof(*s))) == NULL) {
  ------------------
  |  Branch (163:9): [True: 0, False: 73.1k]
  ------------------
  164|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  165|      0|        return NULL;
  166|      0|    }
  167|       |
  168|  73.1k|    if ((s->raw = (zip_uint8_t *)malloc((size_t)length + 1)) == NULL) {
  ------------------
  |  Branch (168:9): [True: 0, False: 73.1k]
  ------------------
  169|      0|        free(s);
  170|      0|        return NULL;
  171|      0|    }
  172|       |
  173|  73.1k|    (void)memcpy_s(s->raw, length + 1, raw, length);
  ------------------
  |  |  202|  73.1k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  174|  73.1k|    s->raw[length] = '\0';
  175|  73.1k|    s->length = length;
  176|  73.1k|    s->encoding = ZIP_ENCODING_UNKNOWN;
  177|  73.1k|    s->converted = NULL;
  178|  73.1k|    s->converted_length = 0;
  179|       |
  180|  73.1k|    if (expected_encoding != ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (180:9): [True: 2.02k, False: 71.1k]
  ------------------
  181|  2.02k|        if (_zip_guess_encoding(s, expected_encoding) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (181:13): [True: 1.65k, False: 377]
  ------------------
  182|  1.65k|            _zip_string_free(s);
  183|  1.65k|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|  1.65k|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  184|  1.65k|            return NULL;
  185|  1.65k|        }
  186|  2.02k|    }
  187|       |
  188|  71.5k|    return s;
  189|  73.1k|}

_zip_unchange_data:
   37|  30.3M|void _zip_unchange_data(zip_entry_t *ze) {
   38|  30.3M|    if (ze->source) {
  ------------------
  |  Branch (38:9): [True: 0, False: 30.3M]
  ------------------
   39|      0|        zip_source_free(ze->source);
   40|      0|        ze->source = NULL;
   41|      0|    }
   42|       |
   43|  30.3M|    ze->deleted = 0;
   44|  30.3M|}

_zip_guess_encoding:
  103|  29.5k|zip_encoding_type_t _zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding) {
  104|  29.5k|    zip_encoding_type_t enc;
  105|  29.5k|    const zip_uint8_t *name;
  106|  29.5k|    zip_uint32_t i, j, ulen, codepoint;
  107|  29.5k|    bool can_be_ascii = true;
  108|  29.5k|    bool can_be_utf8 = true;
  109|  29.5k|    bool has_control_characters = false;
  110|       |
  111|  29.5k|    if (str == NULL) {
  ------------------
  |  Branch (111:9): [True: 0, False: 29.5k]
  ------------------
  112|      0|        return ZIP_ENCODING_ASCII;
  113|      0|    }
  114|       |
  115|  29.5k|    name = str->raw;
  116|       |
  117|  29.5k|    if (str->encoding != ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (117:9): [True: 0, False: 29.5k]
  ------------------
  118|      0|        return str->encoding;
  119|      0|    }
  120|       |
  121|   181k|    for (i = 0; i < str->length; i++) {
  ------------------
  |  Branch (121:17): [True: 155k, False: 26.4k]
  ------------------
  122|   155k|        if (name[i] < 128) {
  ------------------
  |  Branch (122:13): [True: 150k, False: 4.35k]
  ------------------
  123|   150k|            if (name[i] < 32 && name[i] != '\r' && name[i] != '\n' && name[i] != '\t') {
  ------------------
  |  Branch (123:17): [True: 23.9k, False: 126k]
  |  Branch (123:33): [True: 23.3k, False: 607]
  |  Branch (123:52): [True: 22.8k, False: 496]
  |  Branch (123:71): [True: 22.5k, False: 210]
  ------------------
  124|  22.5k|                has_control_characters = true;
  125|  22.5k|            }
  126|   150k|            continue;
  127|   150k|        }
  128|       |
  129|  4.35k|        can_be_ascii = false;
  130|  4.35k|        if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) {
  ------------------
  |  |   89|  4.35k|#define UTF_8_LEN_2_MASK 0xe0
  ------------------
                      if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) {
  ------------------
  |  |   90|  4.35k|#define UTF_8_LEN_2_MATCH 0xc0
  ------------------
  |  Branch (130:13): [True: 832, False: 3.52k]
  ------------------
  131|    832|            ulen = 1;
  132|    832|            codepoint = name[i] & ~UTF_8_LEN_2_MASK;
  ------------------
  |  |   89|    832|#define UTF_8_LEN_2_MASK 0xe0
  ------------------
  133|    832|        }
  134|  3.52k|        else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) {
  ------------------
  |  |   91|  3.52k|#define UTF_8_LEN_3_MASK 0xf0
  ------------------
                      else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) {
  ------------------
  |  |   92|  3.52k|#define UTF_8_LEN_3_MATCH 0xe0
  ------------------
  |  Branch (134:18): [True: 1.05k, False: 2.46k]
  ------------------
  135|  1.05k|            ulen = 2;
  136|  1.05k|            codepoint = name[i] & ~UTF_8_LEN_3_MASK;
  ------------------
  |  |   91|  1.05k|#define UTF_8_LEN_3_MASK 0xf0
  ------------------
  137|  1.05k|        }
  138|  2.46k|        else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) {
  ------------------
  |  |   93|  2.46k|#define UTF_8_LEN_4_MASK 0xf8
  ------------------
                      else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) {
  ------------------
  |  |   94|  2.46k|#define UTF_8_LEN_4_MATCH 0xf0
  ------------------
  |  Branch (138:18): [True: 787, False: 1.67k]
  ------------------
  139|    787|            ulen = 3;
  140|    787|            codepoint = name[i] & ~UTF_8_LEN_4_MASK;
  ------------------
  |  |   93|    787|#define UTF_8_LEN_4_MASK 0xf8
  ------------------
  141|    787|        }
  142|  1.67k|        else {
  143|  1.67k|            can_be_utf8 = false;
  144|  1.67k|            break;
  145|  1.67k|        }
  146|       |
  147|  2.67k|        if (i + ulen >= str->length) {
  ------------------
  |  Branch (147:13): [True: 458, False: 2.21k]
  ------------------
  148|    458|            can_be_utf8 = false;
  149|    458|            break;
  150|    458|        }
  151|       |
  152|  5.34k|        for (j = 1; j <= ulen; j++) {
  ------------------
  |  Branch (152:21): [True: 4.04k, False: 1.29k]
  ------------------
  153|  4.04k|            if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
  ------------------
  |  |   95|  4.04k|#define UTF_8_CONTINUE_MASK 0xc0
  ------------------
                          if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
  ------------------
  |  |   96|  4.04k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  |  Branch (153:17): [True: 924, False: 3.12k]
  ------------------
  154|    924|                can_be_utf8 = false;
  155|    924|                goto done;
  156|    924|            }
  157|  3.12k|            codepoint = (codepoint << 6) | (name[i + j] & UTF_8_CONTINUE_VALUE_MASK);
  ------------------
  |  |   97|  3.12k|#define UTF_8_CONTINUE_VALUE_MASK 0x3f
  ------------------
  158|  3.12k|        }
  159|       |
  160|       |        /* reject overlong encodings, surrogate halves, and code points above U+10FFFF */
  161|  1.29k|        if (codepoint < _utf8_minimum_code_point[ulen] || (codepoint >= 0xd800 && codepoint <= 0xdfff) || codepoint > 0x10ffff) {
  ------------------
  |  Branch (161:13): [True: 5, False: 1.29k]
  |  Branch (161:60): [True: 694, False: 596]
  |  Branch (161:83): [True: 6, False: 688]
  |  Branch (161:107): [True: 12, False: 1.27k]
  ------------------
  162|     23|            can_be_utf8 = false;
  163|     23|            goto done;
  164|     23|        }
  165|  1.27k|        i += ulen;
  166|  1.27k|    }
  167|       |
  168|  29.5k|done:
  169|  29.5k|    enc = ZIP_ENCODING_CP437;
  170|       |
  171|  29.5k|    switch (expected_encoding) {
  ------------------
  |  Branch (171:13): [True: 29.5k, False: 0]
  ------------------
  172|  5.76k|    case ZIP_ENCODING_UTF8_KNOWN:
  ------------------
  |  Branch (172:5): [True: 5.76k, False: 23.7k]
  ------------------
  173|  5.76k|    case ZIP_ENCODING_UTF8_GUESSED:
  ------------------
  |  Branch (173:5): [True: 0, False: 29.5k]
  ------------------
  174|  5.76k|        if (can_be_utf8) {
  ------------------
  |  Branch (174:13): [True: 4.09k, False: 1.66k]
  ------------------
  175|  4.09k|            enc = ZIP_ENCODING_UTF8_KNOWN;
  176|  4.09k|        }
  177|  1.66k|        else {
  178|  1.66k|            enc = ZIP_ENCODING_ERROR;
  179|  1.66k|        }
  180|  5.76k|        break;
  181|       |
  182|      0|    case ZIP_ENCODING_ASCII:
  ------------------
  |  Branch (182:5): [True: 0, False: 29.5k]
  ------------------
  183|      0|        if (can_be_ascii && !has_control_characters) {
  ------------------
  |  Branch (183:13): [True: 0, False: 0]
  |  Branch (183:29): [True: 0, False: 0]
  ------------------
  184|      0|            enc = ZIP_ENCODING_ASCII;
  185|      0|        }
  186|      0|        else {
  187|      0|            enc = ZIP_ENCODING_ERROR;
  188|      0|        }
  189|      0|        break;
  190|       |
  191|      0|    case ZIP_ENCODING_CP437:
  ------------------
  |  Branch (191:5): [True: 0, False: 29.5k]
  ------------------
  192|      0|        enc = ZIP_ENCODING_CP437;
  193|      0|        break;
  194|       |
  195|  23.7k|    case ZIP_ENCODING_UNKNOWN:
  ------------------
  |  Branch (195:5): [True: 23.7k, False: 5.76k]
  ------------------
  196|  23.7k|        if (can_be_ascii && !has_control_characters) {
  ------------------
  |  Branch (196:13): [True: 22.2k, False: 1.44k]
  |  Branch (196:29): [True: 20.8k, False: 1.43k]
  ------------------
  197|       |            /* only bytes from 0x20-0x7F */
  198|  20.8k|            enc = ZIP_ENCODING_ASCII;
  199|  20.8k|        }
  200|  2.88k|        else if (can_be_ascii && has_control_characters) {
  ------------------
  |  Branch (200:18): [True: 1.43k, False: 1.44k]
  |  Branch (200:34): [True: 1.43k, False: 0]
  ------------------
  201|       |            /* only bytes from 0x00-0x7F */
  202|  1.43k|            enc = ZIP_ENCODING_CP437;
  203|  1.43k|        }
  204|  1.44k|        else if (can_be_utf8) {
  ------------------
  |  Branch (204:18): [True: 35, False: 1.41k]
  ------------------
  205|       |            /* contains bytes from 0x80-0xFF and is valid UTF-8 */
  206|     35|            enc = ZIP_ENCODING_UTF8_GUESSED;
  207|     35|        }
  208|  1.41k|        else {
  209|       |            /* fallback */
  210|  1.41k|            enc = ZIP_ENCODING_CP437;
  211|  1.41k|        }
  212|  23.7k|        break;
  213|      0|    case ZIP_ENCODING_ERROR:
  ------------------
  |  Branch (213:5): [True: 0, False: 29.5k]
  ------------------
  214|       |        /* invalid, shouldn't happen */
  215|      0|        enc = ZIP_ENCODING_ERROR;
  216|      0|        break;
  217|  29.5k|    }
  218|       |
  219|  29.5k|    str->encoding = enc;
  220|  29.5k|    return enc;
  221|  29.5k|}
_zip_cp437_to_utf8:
  262|  2.84k|zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t *const _cp437buf, zip_uint32_t len, zip_uint32_t *utf8_lenp, zip_error_t *error) {
  263|  2.84k|    zip_uint8_t *cp437buf = (zip_uint8_t *)_cp437buf;
  264|  2.84k|    zip_uint8_t *utf8buf;
  265|  2.84k|    zip_uint32_t buflen, i, offset;
  266|       |
  267|  2.84k|    if (len == 0) {
  ------------------
  |  Branch (267:9): [True: 0, False: 2.84k]
  ------------------
  268|      0|        if (utf8_lenp) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  269|      0|            *utf8_lenp = 0;
  270|      0|        }
  271|      0|        return NULL;
  272|      0|    }
  273|       |
  274|  2.84k|    buflen = 1;
  275|   848k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (275:17): [True: 845k, False: 2.84k]
  ------------------
  276|   845k|        buflen += _zip_unicode_to_utf8_len(_cp437_to_unicode[cp437buf[i]]);
  277|   845k|    }
  278|       |
  279|  2.84k|    if ((utf8buf = (zip_uint8_t *)malloc(buflen)) == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 2.84k]
  ------------------
  280|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  281|      0|        return NULL;
  282|      0|    }
  283|       |
  284|  2.84k|    offset = 0;
  285|   848k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (285:17): [True: 845k, False: 2.84k]
  ------------------
  286|   845k|        offset += _zip_unicode_to_utf8(_cp437_to_unicode[cp437buf[i]], utf8buf + offset);
  287|   845k|    }
  288|       |
  289|  2.84k|    utf8buf[buflen - 1] = 0;
  290|  2.84k|    if (utf8_lenp) {
  ------------------
  |  Branch (290:9): [True: 2.84k, False: 0]
  ------------------
  291|  2.84k|        *utf8_lenp = buflen - 1;
  292|  2.84k|    }
  293|  2.84k|    return utf8buf;
  294|  2.84k|}
zip_utf-8.c:_zip_unicode_to_utf8_len:
  224|   845k|static zip_uint32_t _zip_unicode_to_utf8_len(zip_uint32_t codepoint) {
  225|   845k|    if (codepoint < 0x0080) {
  ------------------
  |  Branch (225:9): [True: 587k, False: 258k]
  ------------------
  226|   587k|        return 1;
  227|   587k|    }
  228|   258k|    if (codepoint < 0x0800) {
  ------------------
  |  Branch (228:9): [True: 134k, False: 123k]
  ------------------
  229|   134k|        return 2;
  230|   134k|    }
  231|   123k|    if (codepoint < 0x10000) {
  ------------------
  |  Branch (231:9): [True: 123k, False: 0]
  ------------------
  232|   123k|        return 3;
  233|   123k|    }
  234|      0|    return 4;
  235|   123k|}
zip_utf-8.c:_zip_unicode_to_utf8:
  238|   845k|static zip_uint32_t _zip_unicode_to_utf8(zip_uint32_t codepoint, zip_uint8_t *buf) {
  239|   845k|    if (codepoint < 0x0080) {
  ------------------
  |  Branch (239:9): [True: 587k, False: 258k]
  ------------------
  240|   587k|        buf[0] = codepoint & 0xff;
  241|   587k|        return 1;
  242|   587k|    }
  243|   258k|    if (codepoint < 0x0800) {
  ------------------
  |  Branch (243:9): [True: 134k, False: 123k]
  ------------------
  244|   134k|        buf[0] = (zip_uint8_t)(UTF_8_LEN_2_MATCH | ((codepoint >> 6) & 0x1f));
  ------------------
  |  |   90|   134k|#define UTF_8_LEN_2_MATCH 0xc0
  ------------------
  245|   134k|        buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
  ------------------
  |  |   96|   134k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  246|   134k|        return 2;
  247|   134k|    }
  248|   123k|    if (codepoint < 0x10000) {
  ------------------
  |  Branch (248:9): [True: 123k, False: 0]
  ------------------
  249|   123k|        buf[0] = (zip_uint8_t)(UTF_8_LEN_3_MATCH | ((codepoint >> 12) & 0x0f));
  ------------------
  |  |   92|   123k|#define UTF_8_LEN_3_MATCH 0xe0
  ------------------
  250|   123k|        buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f));
  ------------------
  |  |   96|   123k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  251|   123k|        buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
  ------------------
  |  |   96|   123k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  252|   123k|        return 3;
  253|   123k|    }
  254|      0|    buf[0] = (zip_uint8_t)(UTF_8_LEN_4_MATCH | ((codepoint >> 18) & 0x07));
  ------------------
  |  |   94|      0|#define UTF_8_LEN_4_MATCH 0xf0
  ------------------
  255|      0|    buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 12) & 0x3f));
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  256|      0|    buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f));
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  257|      0|    buf[3] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  258|      0|    return 4;
  259|   123k|}

LLVMFuzzerTestOneInput:
   56|  3.72k|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   57|  3.72k|    zip_source_t *src;
   58|  3.72k|    zip_error_t   error;
   59|  3.72k|    zip_t        *za;
   60|       |
   61|  3.72k|    zip_error_init(&error);
   62|       |
   63|  3.72k|    src = zip_source_buffer_create(data, size, 0, &error);
   64|  3.72k|    if (src == NULL) {
  ------------------
  |  Branch (64:9): [True: 0, False: 3.72k]
  ------------------
   65|      0|        zip_error_fini(&error);
   66|      0|        return 0;
   67|      0|    }
   68|       |
   69|  3.72k|    za = zip_open_from_source(src, ZIP_RDONLY, &error);
  ------------------
  |  |   90|  3.72k|#define ZIP_RDONLY 16
  ------------------
   70|  3.72k|    if (za == NULL) {
  ------------------
  |  Branch (70:9): [True: 2.51k, False: 1.20k]
  ------------------
   71|  2.51k|        zip_error_fini(&error);
   72|  2.51k|        zip_source_free(src);
   73|  2.51k|        return 0;
   74|  2.51k|    }
   75|  1.20k|    zip_error_fini(&error);
   76|       |
   77|       |    /* Archive-level comment */
   78|  1.20k|    int comment_len = 0;
   79|  1.20k|    (void)zip_get_archive_comment(za, &comment_len, 0);
   80|       |
   81|  1.20k|    zip_int64_t n = zip_get_num_entries(za, 0);
   82|       |
   83|  24.9k|    for (zip_int64_t i = 0; i < n; i++) {
  ------------------
  |  Branch (83:29): [True: 23.7k, False: 1.20k]
  ------------------
   84|       |        /* 1. stat */
   85|  23.7k|        zip_stat_t st;
   86|  23.7k|        zip_stat_init(&st);
   87|  23.7k|        zip_stat_index(za, (zip_uint64_t)i, 0, &st);
   88|       |
   89|       |        /* 2. external attributes */
   90|  23.7k|        zip_uint8_t  opsys  = 0;
   91|  23.7k|        zip_uint32_t attrib = 0;
   92|  23.7k|        zip_file_get_external_attributes(za, (zip_uint64_t)i, 0, &opsys, &attrib);
   93|       |
   94|       |        /* 3. per-file comment */
   95|  23.7k|        zip_uint32_t fcomment_len = 0;
   96|  23.7k|        (void)zip_file_get_comment(za, (zip_uint64_t)i, &fcomment_len, 0);
   97|       |
   98|       |        /* 4a. enumerate extra fields by index */
   99|  23.7k|        zip_int16_t n_extra = zip_file_extra_fields_count(za, (zip_uint64_t)i, ZIP_FL_LOCAL);
  ------------------
  |  |  104|  23.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  100|   111k|        for (zip_int16_t j = 0; j < n_extra && j < 64; j++) {
  ------------------
  |  Branch (100:33): [True: 89.3k, False: 22.5k]
  |  Branch (100:48): [True: 88.1k, False: 1.23k]
  ------------------
  101|  88.1k|            zip_uint16_t ef_id  = 0;
  102|  88.1k|            zip_uint16_t ef_len = 0;
  103|  88.1k|            (void)zip_file_extra_field_get(za, (zip_uint64_t)i, (zip_uint16_t)j,
  104|  88.1k|                                           &ef_id, &ef_len, ZIP_FL_LOCAL);
  ------------------
  |  |  104|  88.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  105|  88.1k|        }
  106|       |        /* central-directory extra fields too */
  107|  23.7k|        n_extra = zip_file_extra_fields_count(za, (zip_uint64_t)i, ZIP_FL_CENTRAL);
  ------------------
  |  |  105|  23.7k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
  108|  24.7k|        for (zip_int16_t j = 0; j < n_extra && j < 64; j++) {
  ------------------
  |  Branch (108:33): [True: 1.04k, False: 23.7k]
  |  Branch (108:48): [True: 1.04k, False: 2]
  ------------------
  109|  1.04k|            zip_uint16_t ef_id  = 0;
  110|  1.04k|            zip_uint16_t ef_len = 0;
  111|  1.04k|            (void)zip_file_extra_field_get(za, (zip_uint64_t)i, (zip_uint16_t)j,
  112|  1.04k|                                           &ef_id, &ef_len, ZIP_FL_CENTRAL);
  ------------------
  |  |  105|  1.04k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
  113|  1.04k|        }
  114|       |
  115|       |        /* 4b. look up specific well-known extra field IDs */
  116|   166k|        for (size_t k = 0; k < N_PROBE_IDS; k++) {
  ------------------
  |  |   50|   166k|#define N_PROBE_IDS (sizeof(PROBE_IDS) / sizeof(PROBE_IDS[0]))
  ------------------
  |  Branch (116:28): [True: 142k, False: 23.7k]
  ------------------
  117|   142k|            zip_uint16_t ef_len = 0;
  118|       |            /* occurrence 0 - local header */
  119|   142k|            (void)zip_file_extra_field_get_by_id(za, (zip_uint64_t)i,
  120|   142k|                                                  PROBE_IDS[k], 0,
  121|   142k|                                                  &ef_len, ZIP_FL_LOCAL);
  ------------------
  |  |  104|   142k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  122|       |            /* occurrence 0 - central directory */
  123|   142k|            (void)zip_file_extra_field_get_by_id(za, (zip_uint64_t)i,
  124|   142k|                                                  PROBE_IDS[k], 0,
  125|   142k|                                                  &ef_len, ZIP_FL_CENTRAL);
  ------------------
  |  |  105|   142k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
  126|   142k|        }
  127|  23.7k|    }
  128|       |
  129|  1.20k|    if (zip_close(za) < 0) {
  ------------------
  |  Branch (129:9): [True: 0, False: 1.20k]
  ------------------
  130|      0|        zip_discard(za);
  131|      0|    }
  132|  1.20k|    return 0;
  133|  3.72k|}

