_zip_add_entry:
   42|    490|zip_int64_t _zip_add_entry(zip_t *za) {
   43|    490|    zip_uint64_t idx;
   44|       |
   45|    490|    if (za->nentry + 1 >= za->nentry_alloc) {
  ------------------
  |  Branch (45:9): [True: 490, False: 0]
  ------------------
   46|    490|        zip_uint64_t additional_entries = 2 * za->nentry_alloc;
   47|       |
   48|    490|        if (additional_entries < 16) {
  ------------------
  |  Branch (48:13): [True: 490, False: 0]
  ------------------
   49|    490|            additional_entries = 16;
   50|    490|        }
   51|      0|        else if (additional_entries > 1024) {
  ------------------
  |  Branch (51:18): [True: 0, False: 0]
  ------------------
   52|      0|            additional_entries = 1024;
   53|      0|        }
   54|       |
   55|    490|        if (!ZIP_REALLOC(za->entry, za->nentry_alloc, additional_entries, &za->error)) {
  ------------------
  |  |  107|    490|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (55:13): [True: 0, False: 490]
  ------------------
   56|      0|            return -1;
   57|      0|        }
   58|    490|    }
   59|       |
   60|    490|    idx = za->nentry++;
   61|       |
   62|    490|    _zip_entry_init(za->entry + idx);
   63|       |
   64|    490|    return (zip_int64_t)idx;
   65|    490|}

zip_algorithm_deflate.c:maximum_compressed_size:
   50|    490|static zip_uint64_t maximum_compressed_size(zip_uint64_t uncompressed_size) {
   51|       |    /* max deflate size increase: size + ceil(size/16k)*5+6 */
   52|       |
   53|    490|    zip_uint64_t compressed_size = uncompressed_size + (uncompressed_size + 16383) / 16384 * 5 + 6;
   54|       |
   55|    490|    if (compressed_size < uncompressed_size) {
  ------------------
  |  Branch (55:9): [True: 0, False: 490]
  ------------------
   56|      0|        return ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   57|      0|    }
   58|    490|    return compressed_size;
   59|    490|}
zip_algorithm_deflate.c:compress_allocate:
   89|    490|static void *compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
   90|    490|    (void)method;
   91|       |    return allocate(true, compression_flags, error);
   92|    490|}
zip_algorithm_deflate.c:allocate:
   62|    490|static void *allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error) {
   63|    490|    struct ctx *ctx;
   64|       |
   65|    490|    if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (65:9): [True: 0, False: 490]
  ------------------
   66|      0|        zip_error_set(error, ZIP_ET_SYS, errno);
  ------------------
  |  |  172|      0|#define ZIP_ET_SYS 1    /* sys_err is errno */
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|    490|    ctx->error = error;
   71|    490|    ctx->compress = compress;
   72|    490|    if (compression_flags >= 1 && compression_flags <= 9) {
  ------------------
  |  Branch (72:9): [True: 0, False: 490]
  |  Branch (72:35): [True: 0, False: 0]
  ------------------
   73|      0|        ctx->level = (int)compression_flags;
   74|      0|    }
   75|    490|    else {
   76|    490|        ctx->level = Z_BEST_COMPRESSION;
   77|    490|    }
   78|    490|    ctx->mem_level = compression_flags == TORRENTZIP_COMPRESSION_FLAGS ? TORRENTZIP_MEM_LEVEL : MAX_MEM_LEVEL;
  ------------------
  |  |   75|    490|#define TORRENTZIP_COMPRESSION_FLAGS ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    490|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
                  ctx->mem_level = compression_flags == TORRENTZIP_COMPRESSION_FLAGS ? TORRENTZIP_MEM_LEVEL : MAX_MEM_LEVEL;
  ------------------
  |  |   74|      0|#define TORRENTZIP_MEM_LEVEL 8
  ------------------
  |  Branch (78:22): [True: 0, False: 490]
  ------------------
   79|    490|    ctx->end_of_input = false;
   80|       |
   81|    490|    ctx->zstr.zalloc = Z_NULL;
   82|    490|    ctx->zstr.zfree = Z_NULL;
   83|    490|    ctx->zstr.opaque = NULL;
   84|       |
   85|    490|    return ctx;
   86|    490|}
zip_algorithm_deflate.c:deallocate:
  101|    490|static void deallocate(void *ud) {
  102|    490|    struct ctx *ctx = (struct ctx *)ud;
  103|       |
  104|    490|    free(ctx);
  105|    490|}
zip_algorithm_deflate.c:general_purpose_bit_flags:
  108|    849|static zip_uint16_t general_purpose_bit_flags(void *ud) {
  109|    849|    struct ctx *ctx = (struct ctx *)ud;
  110|       |
  111|    849|    if (!ctx->compress) {
  ------------------
  |  Branch (111:9): [True: 0, False: 849]
  ------------------
  112|      0|        return 0;
  113|      0|    }
  114|       |
  115|    849|    if (ctx->level < 3) {
  ------------------
  |  Branch (115:9): [True: 0, False: 849]
  ------------------
  116|      0|        return 2 << 1;
  117|      0|    }
  118|    849|    else if (ctx->level > 7) {
  ------------------
  |  Branch (118:14): [True: 849, False: 0]
  ------------------
  119|    849|        return 1 << 1;
  120|    849|    }
  121|      0|    return 0;
  122|    849|}
zip_algorithm_deflate.c:start:
  125|    490|static bool start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
  126|    490|    struct ctx *ctx = (struct ctx *)ud;
  127|    490|    int ret;
  128|       |
  129|    490|    (void)st;
  130|    490|    (void)attributes;
  131|       |
  132|    490|    ctx->zstr.avail_in = 0;
  133|    490|    ctx->zstr.next_in = NULL;
  134|    490|    ctx->zstr.avail_out = 0;
  135|    490|    ctx->zstr.next_out = NULL;
  136|       |
  137|    490|    if (ctx->compress) {
  ------------------
  |  Branch (137:9): [True: 490, False: 0]
  ------------------
  138|       |        /* negative value to tell zlib not to write a header */
  139|    490|        ret = deflateInit2(&ctx->zstr, ctx->level, Z_DEFLATED, -MAX_WBITS, ctx->mem_level, Z_DEFAULT_STRATEGY);
  140|    490|    }
  141|      0|    else {
  142|      0|        ret = inflateInit2(&ctx->zstr, -MAX_WBITS);
  143|      0|    }
  144|       |
  145|    490|    if (ret != Z_OK) {
  ------------------
  |  Branch (145:9): [True: 0, False: 490]
  ------------------
  146|      0|        zip_error_set(ctx->error, ZIP_ER_ZLIB, ret);
  ------------------
  |  |  144|      0|#define ZIP_ER_ZLIB 13            /* Z Zlib error */
  ------------------
  147|      0|        return false;
  148|      0|    }
  149|       |
  150|       |
  151|    490|    return true;
  152|    490|}
zip_algorithm_deflate.c:end:
  155|    490|static bool end(void *ud) {
  156|    490|    struct ctx *ctx = (struct ctx *)ud;
  157|    490|    int err;
  158|       |
  159|    490|    if (ctx->compress) {
  ------------------
  |  Branch (159:9): [True: 490, False: 0]
  ------------------
  160|    490|        err = deflateEnd(&ctx->zstr);
  161|    490|    }
  162|      0|    else {
  163|      0|        err = inflateEnd(&ctx->zstr);
  164|      0|    }
  165|       |
  166|    490|    if (err != Z_OK) {
  ------------------
  |  Branch (166:9): [True: 0, False: 490]
  ------------------
  167|      0|        zip_error_set(ctx->error, ZIP_ER_ZLIB, err);
  ------------------
  |  |  144|      0|#define ZIP_ER_ZLIB 13            /* Z Zlib error */
  ------------------
  168|      0|        return false;
  169|      0|    }
  170|       |
  171|    490|    return true;
  172|    490|}
zip_algorithm_deflate.c:input:
  175|  12.8k|static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
  176|  12.8k|    struct ctx *ctx = (struct ctx *)ud;
  177|       |
  178|  12.8k|    if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
  ------------------
  |  Branch (178:9): [True: 0, False: 12.8k]
  |  Branch (178:30): [True: 0, False: 12.8k]
  ------------------
  179|      0|        zip_error_set(ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  180|      0|        return false;
  181|      0|    }
  182|       |
  183|  12.8k|    ctx->zstr.avail_in = (uInt)length;
  184|  12.8k|    ctx->zstr.next_in = (Bytef *)data;
  185|       |
  186|       |    return true;
  187|  12.8k|}
zip_algorithm_deflate.c:end_of_input:
  190|    490|static bool end_of_input(void *ud) {
  191|    490|    struct ctx *ctx = (struct ctx *)ud;
  192|       |
  193|       |    ctx->end_of_input = true;
  194|    490|    return ctx->zstr.avail_in != 0;
  195|    490|}
zip_algorithm_deflate.c:process:
  198|  37.4k|static zip_compression_status_t process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
  199|  37.4k|    struct ctx *ctx = (struct ctx *)ud;
  200|  37.4k|    uInt avail_out;
  201|       |
  202|  37.4k|    int ret;
  203|       |
  204|  37.4k|    avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
  ------------------
  |  |  503|  37.4k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 0, False: 37.4k]
  |  |  ------------------
  ------------------
  205|  37.4k|    ctx->zstr.avail_out = avail_out;
  206|  37.4k|    ctx->zstr.next_out = (Bytef *)data;
  207|       |
  208|  37.4k|    if (ctx->compress) {
  ------------------
  |  Branch (208:9): [True: 37.4k, False: 0]
  ------------------
  209|  37.4k|        ret = deflate(&ctx->zstr, ctx->end_of_input ? Z_FINISH : 0);
  ------------------
  |  Branch (209:35): [True: 1.05k, False: 36.4k]
  ------------------
  210|  37.4k|    }
  211|      0|    else {
  212|      0|        ret = inflate(&ctx->zstr, Z_SYNC_FLUSH);
  213|      0|    }
  214|       |
  215|  37.4k|    *length = avail_out - ctx->zstr.avail_out;
  216|       |
  217|  37.4k|    switch (ret) {
  218|  23.6k|    case Z_OK:
  ------------------
  |  Branch (218:5): [True: 23.6k, False: 13.8k]
  ------------------
  219|  23.6k|        return ZIP_COMPRESSION_OK;
  220|       |
  221|    490|    case Z_STREAM_END:
  ------------------
  |  Branch (221:5): [True: 490, False: 36.9k]
  ------------------
  222|    490|        return ZIP_COMPRESSION_END;
  223|       |
  224|  13.3k|    case Z_BUF_ERROR:
  ------------------
  |  Branch (224:5): [True: 13.3k, False: 24.1k]
  ------------------
  225|  13.3k|        if (ctx->zstr.avail_in == 0) {
  ------------------
  |  Branch (225:13): [True: 13.3k, False: 0]
  ------------------
  226|  13.3k|            return ZIP_COMPRESSION_NEED_DATA;
  227|  13.3k|        }
  228|       |
  229|       |        /* fallthrough */
  230|       |
  231|      0|    default:
  ------------------
  |  Branch (231:5): [True: 0, False: 37.4k]
  ------------------
  232|      0|        zip_error_set(ctx->error, ZIP_ER_ZLIB, ret);
  ------------------
  |  |  144|      0|#define ZIP_ER_ZLIB 13            /* Z Zlib error */
  ------------------
  233|      0|        return ZIP_COMPRESSION_ERROR;
  234|  37.4k|    }
  235|  37.4k|}

_zip_buffer_data:
   39|  1.47k|zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer) {
   40|  1.47k|    return buffer->data;
   41|  1.47k|}
_zip_buffer_free:
   44|  3.92k|void _zip_buffer_free(zip_buffer_t *buffer) {
   45|  3.92k|    if (buffer == NULL) {
  ------------------
  |  Branch (45:9): [True: 980, False: 2.94k]
  ------------------
   46|    980|        return;
   47|    980|    }
   48|       |
   49|  2.94k|    if (buffer->free_data) {
  ------------------
  |  Branch (49:9): [True: 980, False: 1.96k]
  ------------------
   50|    980|        free(buffer->data);
   51|    980|    }
   52|       |
   53|  2.94k|    free(buffer);
   54|  2.94k|}
_zip_buffer_eof:
   57|    490|bool _zip_buffer_eof(zip_buffer_t *buffer) {
   58|    490|    return buffer->ok && buffer->offset == buffer->size;
  ------------------
  |  Branch (58:12): [True: 490, False: 0]
  |  Branch (58:26): [True: 490, False: 0]
  ------------------
   59|    490|}
_zip_buffer_get:
   62|  24.9k|zip_uint8_t *_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length) {
   63|  24.9k|    zip_uint8_t *data;
   64|       |
   65|  24.9k|    data = _zip_buffer_peek(buffer, length);
   66|       |
   67|  24.9k|    if (data != NULL) {
  ------------------
  |  Branch (67:9): [True: 24.9k, False: 0]
  ------------------
   68|  24.9k|        buffer->offset += length;
   69|  24.9k|    }
   70|       |
   71|  24.9k|    return data;
   72|  24.9k|}
_zip_buffer_left:
  119|    980|zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer) {
  120|    980|    return buffer->ok ? buffer->size - buffer->offset : 0;
  ------------------
  |  Branch (120:12): [True: 980, False: 0]
  ------------------
  121|    980|}
_zip_buffer_read:
  124|    490|zip_uint64_t _zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
  125|    490|    zip_uint64_t copied;
  126|       |
  127|    490|    if (_zip_buffer_left(buffer) < length) {
  ------------------
  |  Branch (127:9): [True: 490, False: 0]
  ------------------
  128|    490|        length = _zip_buffer_left(buffer);
  129|    490|    }
  130|       |
  131|    490|    copied = 0;
  132|    980|    while (copied < length) {
  ------------------
  |  Branch (132:12): [True: 490, False: 490]
  ------------------
  133|    490|        size_t n = ZIP_MIN(length - copied, SIZE_MAX);
  ------------------
  |  |  503|    490|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 490, False: 0]
  |  |  ------------------
  ------------------
  134|    490|        (void)memcpy_s(data + copied, n, _zip_buffer_get(buffer, n), n);
  ------------------
  |  |  200|    490|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  135|    490|        copied += n;
  136|    490|    }
  137|       |
  138|    490|    return copied;
  139|    490|}
_zip_buffer_new:
  142|  2.94k|zip_buffer_t *_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) {
  143|  2.94k|    bool free_data = (data == NULL);
  144|  2.94k|    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|  2.94k|    if (data == NULL) {
  ------------------
  |  Branch (152:9): [True: 980, False: 1.96k]
  ------------------
  153|    980|        if ((data = (zip_uint8_t *)malloc((size_t)size)) == NULL) {
  ------------------
  |  Branch (153:13): [True: 0, False: 980]
  ------------------
  154|      0|            return NULL;
  155|      0|        }
  156|    980|    }
  157|       |
  158|  2.94k|    if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) {
  ------------------
  |  Branch (158:9): [True: 0, False: 2.94k]
  ------------------
  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|  2.94k|    buffer->ok = true;
  166|  2.94k|    buffer->data = data;
  167|  2.94k|    buffer->size = size;
  168|  2.94k|    buffer->offset = 0;
  169|  2.94k|    buffer->free_data = free_data;
  170|       |
  171|  2.94k|    return buffer;
  172|  2.94k|}
_zip_buffer_offset:
  192|  2.45k|zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer) {
  193|  2.45k|    return buffer->ok ? buffer->offset : 0;
  ------------------
  |  Branch (193:12): [True: 2.45k, False: 0]
  ------------------
  194|  2.45k|}
_zip_buffer_ok:
  197|  2.45k|bool _zip_buffer_ok(zip_buffer_t *buffer) {
  198|  2.45k|    return buffer->ok;
  199|  2.45k|}
_zip_buffer_peek:
  202|  24.9k|zip_uint8_t *_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length) {
  203|  24.9k|    zip_uint8_t *data;
  204|       |
  205|  24.9k|    if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) {
  ------------------
  |  Branch (205:9): [True: 0, False: 24.9k]
  |  Branch (205:24): [True: 0, False: 24.9k]
  |  Branch (205:60): [True: 0, False: 24.9k]
  ------------------
  206|      0|        buffer->ok = false;
  207|      0|        return NULL;
  208|      0|    }
  209|       |
  210|  24.9k|    data = buffer->data + buffer->offset;
  211|  24.9k|    return data;
  212|  24.9k|}
_zip_buffer_put:
  214|  2.45k|int _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) {
  215|  2.45k|    zip_uint8_t *dst = _zip_buffer_get(buffer, length);
  216|       |
  217|  2.45k|    if (dst == NULL) {
  ------------------
  |  Branch (217:9): [True: 0, False: 2.45k]
  ------------------
  218|      0|        return -1;
  219|      0|    }
  220|       |
  221|  2.45k|    (void)memcpy_s(dst, length, src, length);
  ------------------
  |  |  200|  2.45k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  222|  2.45k|    return 0;
  223|  2.45k|}
_zip_buffer_put_16:
  226|  13.7k|int _zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i) {
  227|  13.7k|    zip_uint8_t *data = _zip_buffer_get(buffer, 2);
  228|       |
  229|  13.7k|    if (data == NULL) {
  ------------------
  |  Branch (229:9): [True: 0, False: 13.7k]
  ------------------
  230|      0|        return -1;
  231|      0|    }
  232|       |
  233|  13.7k|    data[0] = (zip_uint8_t)(i & 0xff);
  234|  13.7k|    data[1] = (zip_uint8_t)((i >> 8) & 0xff);
  235|       |
  236|  13.7k|    return 0;
  237|  13.7k|}
_zip_buffer_put_32:
  240|  8.33k|int _zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i) {
  241|  8.33k|    zip_uint8_t *data = _zip_buffer_get(buffer, 4);
  242|       |
  243|  8.33k|    if (data == NULL) {
  ------------------
  |  Branch (243:9): [True: 0, False: 8.33k]
  ------------------
  244|      0|        return -1;
  245|      0|    }
  246|       |
  247|  8.33k|    data[0] = (zip_uint8_t)(i & 0xff);
  248|  8.33k|    data[1] = (zip_uint8_t)((i >> 8) & 0xff);
  249|  8.33k|    data[2] = (zip_uint8_t)((i >> 16) & 0xff);
  250|  8.33k|    data[3] = (zip_uint8_t)((i >> 24) & 0xff);
  251|       |
  252|  8.33k|    return 0;
  253|  8.33k|}

zip_close:
   52|    490|ZIP_EXTERN int zip_close(zip_t *za) {
   53|    490|    zip_uint64_t i, j, survivors, unchanged_offset;
   54|    490|    zip_int64_t off;
   55|    490|    int error;
   56|    490|    zip_filelist_t *filelist;
   57|    490|    int changed;
   58|       |
   59|    490|    if (za == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 490]
  ------------------
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|    490|    changed = _zip_changed(za, &survivors);
   64|       |
   65|    490|    if (survivors == 0 && !(za->ch_flags & ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE)) {
  ------------------
  |  |  116|      0|#define ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE 16u /* don't remove file if archive is empty */
  ------------------
  |  Branch (65:9): [True: 0, False: 490]
  |  Branch (65:27): [True: 0, False: 0]
  ------------------
   66|       |        /* don't create zip files with no entries */
   67|      0|        if ((za->open_flags & ZIP_TRUNCATE) || changed) {
  ------------------
  |  |   89|      0|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (67:13): [True: 0, False: 0]
  |  Branch (67:48): [True: 0, False: 0]
  ------------------
   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|      0|        zip_discard(za);
   76|      0|        return 0;
   77|      0|    }
   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|    490|    if (!changed && survivors > 0) {
  ------------------
  |  Branch (80:9): [True: 0, False: 490]
  |  Branch (80:21): [True: 0, False: 0]
  ------------------
   81|      0|        zip_discard(za);
   82|      0|        return 0;
   83|      0|    }
   84|       |
   85|    490|    if (survivors > za->nentry) {
  ------------------
  |  Branch (85:9): [True: 0, False: 490]
  ------------------
   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|    490|    if ((filelist = (zip_filelist_t *)malloc(sizeof(filelist[0]) * (size_t)survivors)) == NULL) {
  ------------------
  |  Branch (90:9): [True: 0, False: 490]
  ------------------
   91|      0|        return -1;
   92|      0|    }
   93|       |
   94|    490|    unchanged_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|    490|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   95|       |    /* create list of files with index into original archive  */
   96|    980|    for (i = j = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (96:21): [True: 490, False: 490]
  ------------------
   97|    490|        if (za->entry[i].orig != NULL && ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
  ------------------
  |  |  507|      0|#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  506|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (506: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))
  |  |  ------------------
  |  |  |  |  505|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (505:34): [True: 0, False: 0]
  |  |  |  |  |  Branch (505:50): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (507:64): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (97:13): [True: 0, False: 490]
  ------------------
   98|      0|            unchanged_offset = ZIP_MIN(unchanged_offset, za->entry[i].orig->offset);
  ------------------
  |  |  503|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   99|      0|        }
  100|    490|        if (za->entry[i].deleted) {
  ------------------
  |  Branch (100:13): [True: 0, False: 490]
  ------------------
  101|      0|            continue;
  102|      0|        }
  103|       |
  104|    490|        if (j >= survivors) {
  ------------------
  |  Branch (104:13): [True: 0, False: 490]
  ------------------
  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|    490|        filelist[j].idx = i;
  111|    490|        filelist[j].name = zip_get_name(za, i, 0);
  112|    490|        j++;
  113|    490|    }
  114|    490|    if (j < survivors) {
  ------------------
  |  Branch (114:9): [True: 0, False: 490]
  ------------------
  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|    490|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
  121|      0|        qsort(filelist, (size_t)survivors, sizeof(filelist[0]), torrentzip_compare_names);
  122|      0|    }
  123|       |
  124|    490|    if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
  ------------------
  |  |  511|    980|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
                  if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
  ------------------
  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (124:36): [True: 0, False: 490]
  ------------------
  125|      0|        unchanged_offset = 0;
  126|      0|    }
  127|    490|    else {
  128|    490|        if (unchanged_offset == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|    490|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (128:13): [True: 490, False: 0]
  ------------------
  129|       |            /* we're keeping all file data, find the end of the last one */
  130|    490|            zip_uint64_t last_index = ZIP_UINT64_MAX;
  ------------------
  |  |   46|    490|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  131|    490|            unchanged_offset = 0;
  132|       |
  133|    980|            for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (133:25): [True: 490, False: 490]
  ------------------
  134|    490|                if (za->entry[i].orig != NULL) {
  ------------------
  |  Branch (134:21): [True: 0, False: 490]
  ------------------
  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|    490|            }
  141|    490|            if (last_index != ZIP_UINT64_MAX) {
  ------------------
  |  |   46|    490|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (141:17): [True: 0, False: 490]
  ------------------
  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|    490|        }
  148|    490|        if (unchanged_offset > 0) {
  ------------------
  |  Branch (148:13): [True: 0, False: 490]
  ------------------
  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|    490|    }
  155|    490|    if (unchanged_offset == 0) {
  ------------------
  |  Branch (155:9): [True: 490, False: 0]
  ------------------
  156|    490|        if (zip_source_begin_write(za->src) < 0) {
  ------------------
  |  Branch (156:13): [True: 0, False: 490]
  ------------------
  157|      0|            zip_error_set_from_source(&za->error, za->src);
  158|      0|            free(filelist);
  159|      0|            return -1;
  160|      0|        }
  161|    490|    }
  162|       |
  163|    490|    if (_zip_progress_start(za->progress) != 0) {
  ------------------
  |  Branch (163:9): [True: 0, False: 490]
  ------------------
  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|    490|    error = 0;
  170|    980|    for (j = 0; j < survivors; j++) {
  ------------------
  |  Branch (170:17): [True: 490, False: 490]
  ------------------
  171|    490|        int new_data;
  172|    490|        zip_entry_t *entry;
  173|    490|        zip_dirent_t *de;
  174|       |
  175|    490|        if (_zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors) != 0) {
  ------------------
  |  Branch (175:13): [True: 0, False: 490]
  ------------------
  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|    490|        i = filelist[j].idx;
  182|    490|        entry = za->entry + i;
  183|       |
  184|    490|        if (entry->orig != NULL && entry->orig->offset < unchanged_offset) {
  ------------------
  |  Branch (184:13): [True: 0, False: 490]
  |  Branch (184:36): [True: 0, False: 0]
  ------------------
  185|       |            /* already implicitly copied by cloning */
  186|      0|            continue;
  187|      0|        }
  188|       |
  189|    490|        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));
  ------------------
  |  |  506|    980|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  ------------------
  |  |  |  Branch (506:35): [True: 490, 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));
  ------------------
  |  |  505|    490|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  ------------------
  |  |  |  Branch (505:34): [True: 0, False: 0]
  |  |  |  Branch (505: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));
  ------------------
  |  |  505|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  ------------------
  |  |  |  Branch (505:34): [True: 0, False: 0]
  |  |  |  Branch (505: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));
  ------------------
  |  |  511|      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 (511: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));
  ------------------
  |  |  510|      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|    490|        if (entry->changes == NULL) {
  ------------------
  |  Branch (192:13): [True: 0, False: 490]
  ------------------
  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|    490|        else if (entry->orig != NULL) {
  ------------------
  |  Branch (199:18): [True: 0, False: 490]
  ------------------
  200|      0|            if (!_zip_dirent_merge(entry->changes, entry->orig, ZIP_ENTRY_DATA_CHANGED(entry), &za->error)) {
  ------------------
  |  |  506|      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|    490|        de = entry->changes;
  206|       |
  207|    490|        if (_zip_read_local_ef(za, i) < 0) {
  ------------------
  |  Branch (207:13): [True: 0, False: 490]
  ------------------
  208|      0|            error = 1;
  209|      0|            break;
  210|      0|        }
  211|       |
  212|    490|        if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
  213|      0|            zip_dirent_torrentzip_normalize(entry->changes);
  214|      0|        }
  215|       |
  216|    490|        if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (216:13): [True: 0, False: 490]
  ------------------
  217|      0|            zip_error_set_from_source(&za->error, za->src);
  218|      0|            error = 1;
  219|      0|            break;
  220|      0|        }
  221|    490|        de->offset = (zip_uint64_t)off;
  222|       |
  223|    490|        if (new_data) {
  ------------------
  |  Branch (223:13): [True: 490, False: 0]
  ------------------
  224|    490|            zip_source_t *zs;
  225|       |
  226|    490|            zs = NULL;
  227|    490|            if (!ZIP_ENTRY_DATA_CHANGED(entry)) {
  ------------------
  |  |  506|    490|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  ------------------
  |  Branch (227:17): [True: 0, False: 490]
  ------------------
  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|    490|            if (add_data(za, zs ? zs : entry->source, de) < 0) {
  ------------------
  |  Branch (235:17): [True: 0, False: 490]
  |  Branch (235:30): [True: 0, False: 490]
  ------------------
  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|    490|            if (zs) {
  ------------------
  |  Branch (242:17): [True: 0, False: 490]
  ------------------
  243|      0|                zip_source_free(zs);
  244|      0|            }
  245|    490|        }
  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;
  ------------------
  |  |  252|      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) {
  ------------------
  |  |  252|      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|    490|    }
  280|       |
  281|    490|    if (!error) {
  ------------------
  |  Branch (281:9): [True: 490, False: 0]
  ------------------
  282|    490|        if (write_cdir(za, filelist, survivors) < 0) {
  ------------------
  |  Branch (282:13): [True: 0, False: 490]
  ------------------
  283|      0|            error = 1;
  284|      0|        }
  285|    490|    }
  286|       |
  287|    490|    free(filelist);
  288|       |
  289|    490|    if (!error) {
  ------------------
  |  Branch (289:9): [True: 490, False: 0]
  ------------------
  290|    490|        if (zip_source_commit_write(za->src) != 0) {
  ------------------
  |  Branch (290:13): [True: 0, False: 490]
  ------------------
  291|      0|            zip_error_set_from_source(&za->error, za->src);
  292|      0|            error = 1;
  293|      0|        }
  294|    490|        _zip_progress_end(za->progress);
  295|    490|    }
  296|       |
  297|    490|    if (error) {
  ------------------
  |  Branch (297:9): [True: 0, False: 490]
  ------------------
  298|      0|        zip_source_rollback_write(za->src);
  299|      0|        return -1;
  300|      0|    }
  301|       |
  302|    490|    zip_discard(za);
  303|       |
  304|    490|    return 0;
  305|    490|}
_zip_changed:
  731|    490|int _zip_changed(const zip_t *za, zip_uint64_t *survivorsp) {
  732|    490|    int changed;
  733|    490|    zip_uint64_t i, survivors;
  734|       |
  735|    490|    changed = 0;
  736|    490|    survivors = 0;
  737|       |
  738|    490|    if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
  ------------------
  |  |  511|    980|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
                  if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
  ------------------
  |  |  510|      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: 490]
  |  Branch (738:60): [True: 0, False: 0]
  ------------------
  739|      0|        changed = 1;
  740|      0|    }
  741|       |
  742|    980|    for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (742:17): [True: 490, False: 490]
  ------------------
  743|    490|        if (ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
  ------------------
  |  |  507|    490|#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  506|    980|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (506:35): [True: 490, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  505|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (505:34): [True: 0, False: 0]
  |  |  |  |  |  Branch (505:50): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (507:64): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  744|    490|            changed = 1;
  745|    490|        }
  746|    490|        if (!za->entry[i].deleted) {
  ------------------
  |  Branch (746:13): [True: 490, False: 0]
  ------------------
  747|    490|            survivors++;
  748|    490|        }
  749|    490|    }
  750|       |
  751|    490|    if (survivorsp) {
  ------------------
  |  Branch (751:9): [True: 490, False: 0]
  ------------------
  752|    490|        *survivorsp = survivors;
  753|    490|    }
  754|       |
  755|    490|    return changed;
  756|    490|}
zip_close.c:add_data:
  308|    490|static int add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de) {
  309|    490|    zip_int64_t offstart, offdata, offend, data_length;
  310|    490|    zip_stat_t st;
  311|    490|    zip_file_attributes_t attributes;
  312|    490|    zip_source_t *src_final, *src_tmp;
  313|    490|    int ret;
  314|    490|    int is_zip64;
  315|    490|    zip_flags_t flags;
  316|    490|    bool needs_recompress, needs_decompress, needs_crc, needs_compress, needs_reencrypt, needs_decrypt, needs_encrypt;
  317|    490|    bool dirent_changed;
  318|    490|    bool have_dos_time = false;
  319|    490|    time_t mtime_before_copy;
  320|       |
  321|    490|    if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (321:9): [True: 0, False: 490]
  ------------------
  322|      0|        zip_error_set_from_source(&za->error, src);
  323|      0|        return -1;
  324|      0|    }
  325|       |
  326|    490|    de->bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  252|    490|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  327|       |
  328|    490|    if ((st.valid & ZIP_STAT_COMP_METHOD) == 0) {
  ------------------
  |  |  328|    490|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  |  Branch (328:9): [True: 0, False: 490]
  ------------------
  329|      0|        st.valid |= ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  328|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  330|      0|        st.comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  331|      0|    }
  332|       |
  333|    490|    if ((de->changed & ZIP_DIRENT_COMP_METHOD) == 0 && st.comp_method != ZIP_CM_STORE) {
  ------------------
  |  |  333|    490|#define ZIP_DIRENT_COMP_METHOD 0x0001u
  ------------------
                  if ((de->changed & ZIP_DIRENT_COMP_METHOD) == 0 && st.comp_method != ZIP_CM_STORE) {
  ------------------
  |  |  179|    490|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (333:9): [True: 490, False: 0]
  |  Branch (333:56): [True: 0, False: 490]
  ------------------
  334|      0|        de->comp_method = st.comp_method;
  335|      0|    }
  336|    490|    else if (de->comp_method == ZIP_CM_STORE && (st.valid & ZIP_STAT_SIZE)) {
  ------------------
  |  |  179|    980|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
                  else if (de->comp_method == ZIP_CM_STORE && (st.valid & ZIP_STAT_SIZE)) {
  ------------------
  |  |  324|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (336:14): [True: 0, False: 490]
  |  Branch (336:49): [True: 0, False: 0]
  ------------------
  337|      0|        st.valid |= ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  325|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  338|      0|        st.comp_size = st.size;
  339|      0|    }
  340|    490|    else {
  341|       |        /* we'll recompress */
  342|    490|        st.valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  325|    490|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  343|    490|    }
  344|       |
  345|    490|    if ((st.valid & ZIP_STAT_ENCRYPTION_METHOD) == 0) {
  ------------------
  |  |  329|    490|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  |  Branch (345:9): [True: 0, False: 490]
  ------------------
  346|      0|        st.valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  347|      0|        st.encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|      0|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  348|      0|    }
  349|       |
  350|    490|    flags = ZIP_EF_LOCAL;
  ------------------
  |  |  258|    490|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|    490|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  351|       |
  352|    490|    if (st.valid & ZIP_STAT_CRC) {
  ------------------
  |  |  327|    490|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (352:9): [True: 0, False: 490]
  ------------------
  353|      0|        de->crc = st.crc;
  354|      0|    }
  355|       |
  356|    490|    if ((st.valid & ZIP_STAT_SIZE) == 0) {
  ------------------
  |  |  324|    490|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (356:9): [True: 0, False: 490]
  ------------------
  357|       |        /* TODO: not valid for torrentzip */
  358|      0|        flags |= ZIP_FL_FORCE_ZIP64;
  ------------------
  |  |  262|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  359|      0|        data_length = -1;
  360|      0|    }
  361|    490|    else {
  362|    490|        de->uncomp_size = st.size;
  363|       |
  364|    490|        if ((st.valid & ZIP_STAT_COMP_SIZE) == 0) {
  ------------------
  |  |  325|    490|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (364:13): [True: 490, False: 0]
  ------------------
  365|    490|            zip_uint64_t max_compressed_size;
  366|    490|            zip_uint16_t compression_method = ZIP_CM_ACTUAL(de->comp_method);
  ------------------
  |  |   87|    490|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|    490|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    490|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 490, False: 0]
  |  |  ------------------
  ------------------
  367|       |
  368|       |            /* this is technically incorrect (copy_source counts compressed data), but it's the best we have */
  369|    490|            data_length = (zip_int64_t)st.size;
  370|       |
  371|    490|            if (compression_method == ZIP_CM_STORE) {
  ------------------
  |  |  179|    490|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (371:17): [True: 0, False: 490]
  ------------------
  372|      0|                max_compressed_size = st.size;
  373|      0|            }
  374|    490|            else {
  375|    490|                zip_compression_algorithm_t *algorithm = _zip_get_compression_algorithm(compression_method, true);
  376|    490|                if (algorithm == NULL) {
  ------------------
  |  Branch (376:21): [True: 0, False: 490]
  ------------------
  377|      0|                    max_compressed_size = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  378|      0|                }
  379|    490|                else {
  380|    490|                    max_compressed_size = algorithm->maximum_compressed_size(st.size);
  381|    490|                }
  382|    490|            }
  383|       |
  384|    490|            if (max_compressed_size > 0xffffffffu) {
  ------------------
  |  Branch (384:17): [True: 0, False: 490]
  ------------------
  385|       |                /* TODO: not valid for torrentzip */
  386|      0|                flags |= ZIP_FL_FORCE_ZIP64;
  ------------------
  |  |  262|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  387|      0|            }
  388|    490|        }
  389|      0|        else {
  390|      0|            de->comp_size = st.comp_size;
  391|      0|            data_length = (zip_int64_t)st.comp_size;
  392|      0|        }
  393|    490|    }
  394|       |
  395|    490|    if ((de->changed & ZIP_DIRENT_LAST_MOD) == 0) {
  ------------------
  |  |  338|    490|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (395:9): [True: 490, False: 0]
  ------------------
  396|    490|        int ret2 = zip_source_get_dos_time(src, &de->last_mod);
  397|    490|        if (ret2 < 0) {
  ------------------
  |  Branch (397:13): [True: 0, False: 490]
  ------------------
  398|      0|            zip_error_set_from_source(&za->error, src);
  399|      0|            return -1;
  400|      0|        }
  401|    490|        if (ret2 == 1) {
  ------------------
  |  Branch (401:13): [True: 0, False: 490]
  ------------------
  402|      0|            have_dos_time = true;
  403|      0|        }
  404|    490|        else {
  405|    490|            if (st.valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  326|    490|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (405:17): [True: 490, False: 0]
  ------------------
  406|    490|                mtime_before_copy = st.mtime;
  407|    490|            }
  408|      0|            else {
  409|      0|                time(&mtime_before_copy);
  410|      0|            }
  411|    490|            if (_zip_u2d_time(mtime_before_copy, &de->last_mod, &za->error) < 0) {
  ------------------
  |  Branch (411:17): [True: 0, False: 490]
  ------------------
  412|      0|                return -1;
  413|      0|            }
  414|    490|        }
  415|    490|    }
  416|       |
  417|    490|    if ((offstart = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (417:9): [True: 0, False: 490]
  ------------------
  418|      0|        zip_error_set_from_source(&za->error, za->src);
  419|      0|        return -1;
  420|      0|    }
  421|       |
  422|    490|    needs_recompress = ZIP_WANT_TORRENTZIP(za) || st.comp_method != ZIP_CM_ACTUAL(de->comp_method);
  ------------------
  |  |  511|    980|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
                  needs_recompress = ZIP_WANT_TORRENTZIP(za) || st.comp_method != ZIP_CM_ACTUAL(de->comp_method);
  ------------------
  |  |   87|    980|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|    490|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    490|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 490, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (422:51): [True: 490, False: 0]
  ------------------
  423|    490|    needs_decompress = needs_recompress && (st.comp_method != ZIP_CM_STORE);
  ------------------
  |  |  179|    490|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (423:24): [True: 490, False: 0]
  |  Branch (423:44): [True: 0, False: 490]
  ------------------
  424|       |    /* in these cases we can compute the CRC ourselves, so we do */
  425|    490|    needs_crc = (st.comp_method == ZIP_CM_STORE) || needs_decompress;
  ------------------
  |  |  179|    490|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (425:17): [True: 490, False: 0]
  |  Branch (425:53): [True: 0, False: 0]
  ------------------
  426|    490|    needs_compress = needs_recompress && (de->comp_method != ZIP_CM_STORE);
  ------------------
  |  |  179|    490|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (426:22): [True: 490, False: 0]
  |  Branch (426:42): [True: 490, False: 0]
  ------------------
  427|       |
  428|    490|    needs_reencrypt = needs_recompress || (de->changed & ZIP_DIRENT_PASSWORD) || (de->encryption_method != st.encryption_method);
  ------------------
  |  |  340|      0|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (428:23): [True: 490, False: 0]
  |  Branch (428:43): [True: 0, False: 0]
  |  Branch (428:82): [True: 0, False: 0]
  ------------------
  429|    490|    needs_decrypt = needs_reencrypt && (st.encryption_method != ZIP_EM_NONE);
  ------------------
  |  |  207|    490|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (429:21): [True: 490, False: 0]
  |  Branch (429:40): [True: 0, False: 490]
  ------------------
  430|    490|    needs_encrypt = needs_reencrypt && (de->encryption_method != ZIP_EM_NONE);
  ------------------
  |  |  207|    490|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (430:21): [True: 490, False: 0]
  |  Branch (430:40): [True: 490, False: 0]
  ------------------
  431|       |
  432|    490|    src_final = src;
  433|    490|    zip_source_keep(src_final);
  434|       |
  435|    490|    if (!needs_decrypt && st.encryption_method == ZIP_EM_TRAD_PKWARE && (de->changed & ZIP_DIRENT_LAST_MOD)) {
  ------------------
  |  |  208|    980|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
                  if (!needs_decrypt && st.encryption_method == ZIP_EM_TRAD_PKWARE && (de->changed & ZIP_DIRENT_LAST_MOD)) {
  ------------------
  |  |  338|      0|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (435:9): [True: 490, False: 0]
  |  Branch (435:27): [True: 0, False: 490]
  |  Branch (435:73): [True: 0, False: 0]
  ------------------
  436|       |        /* PKWare encryption uses the last modification time for password verification, therefore we can't change it without re-encrypting. Ignoring the requested modification time change seems more sensible than failing to close the archive. */
  437|      0|        de->changed &= ~ZIP_DIRENT_LAST_MOD;
  ------------------
  |  |  338|      0|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  438|      0|    }
  439|       |
  440|    490|    if (needs_decrypt) {
  ------------------
  |  Branch (440:9): [True: 0, False: 490]
  ------------------
  441|      0|        zip_encryption_implementation impl;
  442|       |
  443|      0|        if ((impl = _zip_get_encryption_implementation(st.encryption_method, ZIP_CODEC_DECODE)) == NULL) {
  ------------------
  |  |  114|      0|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (443:13): [True: 0, False: 0]
  ------------------
  444|      0|            zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  445|      0|            zip_source_free(src_final);
  446|      0|            return -1;
  447|      0|        }
  448|      0|        if ((src_tmp = impl(za, src_final, st.encryption_method, ZIP_CODEC_DECODE, za->default_password)) == NULL) {
  ------------------
  |  |  114|      0|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (448:13): [True: 0, False: 0]
  ------------------
  449|       |            /* error set by impl */
  450|      0|            zip_source_free(src_final);
  451|      0|            return -1;
  452|      0|        }
  453|       |
  454|      0|        src_final = src_tmp;
  455|      0|    }
  456|       |
  457|    490|    if (needs_decompress) {
  ------------------
  |  Branch (457:9): [True: 0, False: 490]
  ------------------
  458|      0|        if ((src_tmp = zip_source_decompress(za, src_final, st.comp_method)) == NULL) {
  ------------------
  |  Branch (458:13): [True: 0, False: 0]
  ------------------
  459|      0|            zip_source_free(src_final);
  460|      0|            return -1;
  461|      0|        }
  462|       |
  463|      0|        src_final = src_tmp;
  464|      0|    }
  465|       |
  466|    490|    if (needs_crc) {
  ------------------
  |  Branch (466:9): [True: 490, False: 0]
  ------------------
  467|    490|        if ((src_tmp = zip_source_crc_create(src_final, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (467:13): [True: 0, False: 490]
  ------------------
  468|      0|            zip_source_free(src_final);
  469|      0|            return -1;
  470|      0|        }
  471|       |
  472|    490|        src_final = src_tmp;
  473|    490|    }
  474|       |
  475|    490|    if (needs_compress) {
  ------------------
  |  Branch (475:9): [True: 490, False: 0]
  ------------------
  476|    490|        if ((src_tmp = zip_source_compress(za, src_final, de->comp_method, de->compression_level)) == NULL) {
  ------------------
  |  Branch (476:13): [True: 0, False: 490]
  ------------------
  477|      0|            zip_source_free(src_final);
  478|      0|            return -1;
  479|      0|        }
  480|       |
  481|    490|        src_final = src_tmp;
  482|    490|    }
  483|       |
  484|       |
  485|    490|    if (needs_encrypt) {
  ------------------
  |  Branch (485:9): [True: 490, False: 0]
  ------------------
  486|    490|        zip_encryption_implementation impl;
  487|    490|        const char *password = NULL;
  488|       |
  489|    490|        if (de->password) {
  ------------------
  |  Branch (489:13): [True: 490, False: 0]
  ------------------
  490|    490|            password = de->password;
  491|    490|        }
  492|      0|        else if (za->default_password) {
  ------------------
  |  Branch (492:18): [True: 0, False: 0]
  ------------------
  493|      0|            password = za->default_password;
  494|      0|        }
  495|       |
  496|    490|        if ((impl = _zip_get_encryption_implementation(de->encryption_method, ZIP_CODEC_ENCODE)) == NULL) {
  ------------------
  |  |  115|    490|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (496:13): [True: 0, False: 490]
  ------------------
  497|      0|            zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  498|      0|            zip_source_free(src_final);
  499|      0|            return -1;
  500|      0|        }
  501|       |
  502|    490|        if (de->encryption_method == ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|    490|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (502:13): [True: 490, False: 0]
  ------------------
  503|    490|            de->bitflags |= ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  252|    490|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  504|       |
  505|       |            /* PKWare encryption uses last_mod, make sure it gets the right value. */
  506|    490|            if (de->changed & ZIP_DIRENT_LAST_MOD) {
  ------------------
  |  |  338|    490|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (506:17): [True: 0, False: 490]
  ------------------
  507|      0|                if ((src_tmp = _zip_source_window_new(src_final, 0, -1, NULL, 0, NULL, &de->last_mod, NULL, 0, true, &za->error)) == NULL) {
  ------------------
  |  Branch (507:21): [True: 0, False: 0]
  ------------------
  508|      0|                    zip_source_free(src_final);
  509|      0|                    return -1;
  510|      0|                }
  511|      0|                src_final = src_tmp;
  512|      0|            }
  513|    490|        }
  514|       |
  515|    490|        if ((src_tmp = impl(za, src_final, de->encryption_method, ZIP_CODEC_ENCODE, password)) == NULL) {
  ------------------
  |  |  115|    490|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (515:13): [True: 0, False: 490]
  ------------------
  516|       |            /* error set by impl */
  517|      0|            zip_source_free(src_final);
  518|      0|            return -1;
  519|      0|        }
  520|       |
  521|    490|        src_final = src_tmp;
  522|    490|    }
  523|       |
  524|    490|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (524:9): [True: 490, False: 0]
  ------------------
  525|    490|        if (zip_source_get_file_attributes(src_final, &attributes) != 0) {
  ------------------
  |  Branch (525:13): [True: 0, False: 490]
  ------------------
  526|      0|            zip_error_set_from_source(&za->error, src_final);
  527|      0|            zip_source_free(src_final);
  528|      0|            return -1;
  529|      0|        }
  530|    490|        _zip_dirent_apply_attributes(de, &attributes, (flags & ZIP_FL_FORCE_ZIP64) != 0);
  ------------------
  |  |  262|    490|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  531|    490|    }
  532|       |
  533|       |    /* as long as we don't support non-seekable output, clear data descriptor bit */
  534|    490|    if ((is_zip64 = _zip_dirent_write(za, de, flags)) < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 490]
  ------------------
  535|      0|        zip_source_free(src_final);
  536|      0|        return -1;
  537|      0|    }
  538|       |
  539|    490|    if ((offdata = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (539:9): [True: 0, False: 490]
  ------------------
  540|      0|        zip_error_set_from_source(&za->error, za->src);
  541|      0|        zip_source_free(src_final);
  542|      0|        return -1;
  543|      0|    }
  544|       |
  545|    490|    ret = copy_source(za, src_final, src, data_length);
  546|       |
  547|    490|    if (zip_source_stat(src_final, &st) < 0) {
  ------------------
  |  Branch (547:9): [True: 0, False: 490]
  ------------------
  548|      0|        zip_error_set_from_source(&za->error, src_final);
  549|      0|        ret = -1;
  550|      0|    }
  551|       |
  552|    490|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (552:9): [True: 490, False: 0]
  ------------------
  553|    490|        if (zip_source_get_file_attributes(src_final, &attributes) != 0) {
  ------------------
  |  Branch (553:13): [True: 0, False: 490]
  ------------------
  554|      0|            zip_error_set_from_source(&za->error, src_final);
  555|      0|            ret = -1;
  556|      0|        }
  557|    490|    }
  558|       |
  559|    490|    zip_source_free(src_final);
  560|       |
  561|    490|    if (ret < 0) {
  ------------------
  |  Branch (561:9): [True: 0, False: 490]
  ------------------
  562|      0|        return -1;
  563|      0|    }
  564|       |
  565|    490|    if ((offend = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (565:9): [True: 0, False: 490]
  ------------------
  566|      0|        zip_error_set_from_source(&za->error, za->src);
  567|      0|        return -1;
  568|      0|    }
  569|       |
  570|    490|    if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  328|    490|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  327|    490|#define ZIP_STAT_CRC 0x0020u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  324|    490|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  328|    490|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  327|    490|#define ZIP_STAT_CRC 0x0020u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  324|    490|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (570:9): [True: 0, False: 490]
  ------------------
  571|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  572|      0|        return -1;
  573|      0|    }
  574|       |
  575|    490|    dirent_changed = ZIP_CM_ACTUAL(de->comp_method) != st.comp_method || de->crc != st.crc || de->uncomp_size != st.size || de->comp_size != (zip_uint64_t)(offend - offdata);
  ------------------
  |  |   87|    490|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|    490|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    490|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 490, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (575:22): [True: 131, False: 359]
  |  Branch (575:74): [True: 351, False: 8]
  |  Branch (575:95): [True: 0, False: 8]
  |  Branch (575:125): [True: 8, False: 0]
  ------------------
  576|    490|    de->comp_method = st.comp_method;
  577|    490|    de->crc = st.crc;
  578|    490|    de->uncomp_size = st.size;
  579|    490|    de->comp_size = (zip_uint64_t)(offend - offdata);
  580|       |
  581|    490|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (581:9): [True: 490, False: 0]
  ------------------
  582|    490|        dirent_changed |= _zip_dirent_apply_attributes(de, &attributes, (flags & ZIP_FL_FORCE_ZIP64) != 0);
  ------------------
  |  |  262|    490|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  583|       |
  584|    490|        if ((de->changed & ZIP_DIRENT_LAST_MOD) == 0 && !have_dos_time) {
  ------------------
  |  |  338|    490|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (584:13): [True: 490, False: 0]
  |  Branch (584:57): [True: 490, False: 0]
  ------------------
  585|    490|            if (st.valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  326|    490|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (585:17): [True: 490, False: 0]
  ------------------
  586|    490|                if (st.mtime != mtime_before_copy) {
  ------------------
  |  Branch (586:21): [True: 0, False: 490]
  ------------------
  587|      0|                    if (_zip_u2d_time(st.mtime, &de->last_mod, &za->error) < 0) {
  ------------------
  |  Branch (587:25): [True: 0, False: 0]
  ------------------
  588|      0|                        return -1;
  589|      0|                    }
  590|      0|                    dirent_changed = true;
  591|      0|                }
  592|    490|            }
  593|    490|        }
  594|    490|    }
  595|       |
  596|    490|    if (dirent_changed) {
  ------------------
  |  Branch (596:9): [True: 490, False: 0]
  ------------------
  597|    490|        if (zip_source_seek_write(za->src, offstart, SEEK_SET) < 0) {
  ------------------
  |  Branch (597:13): [True: 0, False: 490]
  ------------------
  598|      0|            zip_error_set_from_source(&za->error, za->src);
  599|      0|            return -1;
  600|      0|        }
  601|       |
  602|    490|        if ((ret = _zip_dirent_write(za, de, flags)) < 0) {
  ------------------
  |  Branch (602:13): [True: 0, False: 490]
  ------------------
  603|      0|            return -1;
  604|      0|        }
  605|       |
  606|    490|        if (is_zip64 != ret) {
  ------------------
  |  Branch (606:13): [True: 0, False: 490]
  ------------------
  607|       |            /* Zip64 mismatch between preliminary file header written before data and final file header written afterwards */
  608|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  609|      0|            return -1;
  610|      0|        }
  611|       |
  612|    490|        if (zip_source_seek_write(za->src, offend, SEEK_SET) < 0) {
  ------------------
  |  Branch (612:13): [True: 0, False: 490]
  ------------------
  613|      0|            zip_error_set_from_source(&za->error, za->src);
  614|      0|            return -1;
  615|      0|        }
  616|    490|    }
  617|       |
  618|    490|    if (de->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
  ------------------
  |  |  252|    490|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  |  Branch (618:9): [True: 490, False: 0]
  ------------------
  619|    490|        if (write_data_descriptor(za, de, is_zip64) < 0) {
  ------------------
  |  Branch (619:13): [True: 0, False: 490]
  ------------------
  620|      0|            return -1;
  621|      0|        }
  622|    490|    }
  623|       |
  624|    490|    return 0;
  625|    490|}
zip_close.c:copy_source:
  663|    490|static int copy_source(zip_t *za, zip_source_t *src, zip_source_t *src_for_length, zip_int64_t data_length) {
  664|    490|    DEFINE_BYTE_ARRAY(buf, BUFSIZE);
  ------------------
  |  |  468|    490|#define DEFINE_BYTE_ARRAY(buf, size) zip_uint8_t buf[size]
  ------------------
  665|    490|    zip_int64_t n, current;
  666|    490|    int ret;
  667|       |
  668|    490|    if (zip_source_open(src) < 0) {
  ------------------
  |  Branch (668:9): [True: 0, False: 490]
  ------------------
  669|      0|        zip_error_set_from_source(&za->error, src);
  670|      0|        return -1;
  671|      0|    }
  672|       |
  673|    490|    if (!byte_array_init(buf, BUFSIZE)) {
  ------------------
  |  |  469|    490|#define byte_array_init(buf, size) (1)
  ------------------
  |  Branch (673:9): [Folded, False: 490]
  ------------------
  674|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  675|      0|        return -1;
  676|      0|    }
  677|       |
  678|    490|    ret = 0;
  679|    490|    current = 0;
  680|  11.2k|    while ((n = zip_source_read(src, buf, BUFSIZE)) > 0) {
  ------------------
  |  |   66|  11.2k|#define BUFSIZE 8192
  ------------------
  |  Branch (680:12): [True: 10.7k, False: 490]
  ------------------
  681|  10.7k|        if (_zip_write(za, buf, (zip_uint64_t)n) < 0) {
  ------------------
  |  Branch (681:13): [True: 0, False: 10.7k]
  ------------------
  682|      0|            ret = -1;
  683|      0|            break;
  684|      0|        }
  685|  10.7k|        if (n == BUFSIZE && za->progress && data_length > 0) {
  ------------------
  |  |   66|  21.4k|#define BUFSIZE 8192
  ------------------
  |  Branch (685:13): [True: 10.2k, False: 469]
  |  Branch (685:29): [True: 0, False: 10.2k]
  |  Branch (685:45): [True: 0, False: 0]
  ------------------
  686|      0|            zip_int64_t t;
  687|      0|            t = zip_source_tell(src_for_length);
  688|      0|            if (t >= 0) {
  ------------------
  |  Branch (688:17): [True: 0, False: 0]
  ------------------
  689|      0|                current = t;
  690|      0|            }
  691|      0|            else {
  692|      0|                current += n;
  693|      0|            }
  694|      0|            if (_zip_progress_update(za->progress, (double)current / (double)data_length) != 0) {
  ------------------
  |  Branch (694:17): [True: 0, False: 0]
  ------------------
  695|      0|                zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
  ------------------
  |  |  163|      0|#define ZIP_ER_CANCELLED 32       /* N Operation cancelled */
  ------------------
  696|      0|                ret = -1;
  697|      0|                break;
  698|      0|            }
  699|      0|        }
  700|  10.7k|    }
  701|       |
  702|    490|    if (n < 0) {
  ------------------
  |  Branch (702:9): [True: 0, False: 490]
  ------------------
  703|      0|        zip_error_set_from_source(&za->error, src);
  704|      0|        ret = -1;
  705|      0|    }
  706|       |
  707|    490|    byte_array_fini(buf);
  ------------------
  |  |  470|    490|#define byte_array_fini(buf) ((void)0)
  ------------------
  708|       |
  709|    490|    zip_source_close(src);
  710|       |
  711|    490|    return ret;
  712|    490|}
zip_close.c:write_cdir:
  714|    490|static int write_cdir(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) {
  715|    490|    if (zip_source_tell_write(za->src) < 0) {
  ------------------
  |  Branch (715:9): [True: 0, False: 490]
  ------------------
  716|      0|        return -1;
  717|      0|    }
  718|       |
  719|    490|    if (_zip_cdir_write(za, filelist, survivors) < 0) {
  ------------------
  |  Branch (719:9): [True: 0, False: 490]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|    490|    if (zip_source_tell_write(za->src) < 0) {
  ------------------
  |  Branch (723:9): [True: 0, False: 490]
  ------------------
  724|      0|        return -1;
  725|      0|    }
  726|       |
  727|    490|    return 0;
  728|    490|}
zip_close.c:write_data_descriptor:
  758|    490|static int write_data_descriptor(zip_t *za, const zip_dirent_t *de, int is_zip64) {
  759|    490|    zip_buffer_t *buffer = _zip_buffer_new(NULL, MAX_DATA_DESCRIPTOR_LENGTH);
  ------------------
  |  |   69|    490|#define MAX_DATA_DESCRIPTOR_LENGTH 24
  ------------------
  760|    490|    int ret = 0;
  761|       |
  762|    490|    if (buffer == NULL) {
  ------------------
  |  Branch (762:9): [True: 0, False: 490]
  ------------------
  763|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  764|      0|        return -1;
  765|      0|    }
  766|       |
  767|    490|    _zip_buffer_put(buffer, DATADES_MAGIC, 4);
  ------------------
  |  |   54|    490|#define DATADES_MAGIC "PK\7\10"
  ------------------
  768|    490|    _zip_buffer_put_32(buffer, de->crc);
  769|    490|    if (is_zip64) {
  ------------------
  |  Branch (769:9): [True: 0, False: 490]
  ------------------
  770|      0|        _zip_buffer_put_64(buffer, de->comp_size);
  771|      0|        _zip_buffer_put_64(buffer, de->uncomp_size);
  772|      0|    }
  773|    490|    else {
  774|    490|        _zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size);
  775|    490|        _zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size);
  776|    490|    }
  777|       |
  778|    490|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (778:9): [True: 0, False: 490]
  ------------------
  779|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  780|      0|        ret = -1;
  781|      0|    }
  782|    490|    else {
  783|    490|        ret = _zip_write(za, _zip_buffer_data(buffer), _zip_buffer_offset(buffer));
  784|    490|    }
  785|       |
  786|    490|    _zip_buffer_free(buffer);
  787|       |
  788|    490|    return ret;
  789|    490|}

zip_secure_random:
  218|    980|ZIP_EXTERN bool zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
  219|    980|    return RAND_bytes(buffer, length) == 1;
  220|    980|}

_zip_cdir_write:
  104|    490|zip_int64_t _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) {
  105|    490|    zip_uint64_t offset, size;
  106|    490|    zip_string_t *comment;
  107|    490|    zip_uint8_t buf[EOCDLEN + EOCD64LEN + EOCD64LOCLEN];
  108|    490|    zip_buffer_t *buffer;
  109|    490|    zip_int64_t off;
  110|    490|    zip_uint64_t i;
  111|    490|    zip_uint32_t cdir_crc;
  112|       |
  113|    490|    if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (113:9): [True: 0, False: 490]
  ------------------
  114|      0|        zip_error_set_from_source(&za->error, za->src);
  115|      0|        return -1;
  116|      0|    }
  117|    490|    offset = (zip_uint64_t)off;
  118|       |
  119|    490|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
  120|      0|        cdir_crc = (zip_uint32_t)crc32(0, NULL, 0);
  121|      0|        za->write_crc = &cdir_crc;
  122|      0|    }
  123|       |
  124|    980|    for (i = 0; i < survivors; i++) {
  ------------------
  |  Branch (124:17): [True: 490, False: 490]
  ------------------
  125|    490|        zip_entry_t *entry = za->entry + filelist[i].idx;
  126|       |
  127|    490|        if (_zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL) < 0) {
  ------------------
  |  |  105|    490|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
  |  Branch (127:13): [True: 0, False: 490]
  |  Branch (127:35): [True: 490, False: 0]
  ------------------
  128|      0|            za->write_crc = NULL;
  129|      0|            return -1;
  130|      0|        }
  131|    490|    }
  132|       |
  133|    490|    za->write_crc = NULL;
  134|       |
  135|    490|    if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (135:9): [True: 0, False: 490]
  ------------------
  136|      0|        zip_error_set_from_source(&za->error, za->src);
  137|      0|        return -1;
  138|      0|    }
  139|    490|    size = (zip_uint64_t)off - offset;
  140|       |
  141|    490|    if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
  ------------------
  |  Branch (141:9): [True: 0, False: 490]
  ------------------
  142|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  143|      0|        return -1;
  144|      0|    }
  145|       |
  146|    490|    if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) {
  ------------------
  |  |   38|    980|#define ZIP_UINT16_MAX	 0xffff
  ------------------
                  if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    980|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    490|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (146:9): [True: 0, False: 490]
  |  Branch (146:39): [True: 0, False: 490]
  |  Branch (146:66): [True: 0, False: 490]
  ------------------
  147|      0|        _zip_buffer_put(buffer, EOCD64_MAGIC, 4);
  ------------------
  |  |   56|      0|#define EOCD64_MAGIC "PK\6\6"
  ------------------
  148|      0|        _zip_buffer_put_64(buffer, EOCD64LEN - 12);
  ------------------
  |  |   64|      0|#define EOCD64LEN 56
  ------------------
  149|      0|        _zip_buffer_put_16(buffer, 45);
  150|      0|        _zip_buffer_put_16(buffer, 45);
  151|      0|        _zip_buffer_put_32(buffer, 0);
  152|      0|        _zip_buffer_put_32(buffer, 0);
  153|      0|        _zip_buffer_put_64(buffer, survivors);
  154|      0|        _zip_buffer_put_64(buffer, survivors);
  155|      0|        _zip_buffer_put_64(buffer, size);
  156|      0|        _zip_buffer_put_64(buffer, offset);
  157|      0|        _zip_buffer_put(buffer, EOCD64LOC_MAGIC, 4);
  ------------------
  |  |   55|      0|#define EOCD64LOC_MAGIC "PK\6\7"
  ------------------
  158|      0|        _zip_buffer_put_32(buffer, 0);
  159|      0|        _zip_buffer_put_64(buffer, offset + size);
  160|      0|        _zip_buffer_put_32(buffer, 1);
  161|      0|    }
  162|       |
  163|    490|    _zip_buffer_put(buffer, EOCD_MAGIC, 4);
  ------------------
  |  |   53|    490|#define EOCD_MAGIC "PK\5\6"
  ------------------
  164|    490|    _zip_buffer_put_32(buffer, 0);
  165|    490|    _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|    490|#define ZIP_UINT16_MAX	 0xffff
  ------------------
                  _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (165:47): [True: 0, False: 490]
  ------------------
  166|    490|    _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|    490|#define ZIP_UINT16_MAX	 0xffff
  ------------------
                  _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (166:47): [True: 0, False: 490]
  ------------------
  167|    490|    _zip_buffer_put_32(buffer, size >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)size);
  ------------------
  |  |   42|    490|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  _zip_buffer_put_32(buffer, size >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)size);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (167:32): [True: 0, False: 490]
  ------------------
  168|    490|    _zip_buffer_put_32(buffer, offset >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)offset);
  ------------------
  |  |   42|    490|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  _zip_buffer_put_32(buffer, offset >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)offset);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (168:32): [True: 0, False: 490]
  ------------------
  169|       |
  170|    490|    comment = za->comment_changed ? za->comment_changes : za->comment_orig;
  ------------------
  |  Branch (170:15): [True: 0, False: 490]
  ------------------
  171|       |
  172|    490|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
  173|      0|        _zip_buffer_put_16(buffer, TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   72|      0|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
                      _zip_buffer_put_16(buffer, TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   73|      0|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  174|      0|    }
  175|    490|    else {
  176|    490|        _zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0));
  ------------------
  |  Branch (176:51): [True: 0, False: 490]
  ------------------
  177|    490|    }
  178|       |
  179|       |
  180|    490|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (180:9): [True: 0, False: 490]
  ------------------
  181|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  182|      0|        _zip_buffer_free(buffer);
  183|      0|        return -1;
  184|      0|    }
  185|       |
  186|    490|    if (_zip_write(za, _zip_buffer_data(buffer), _zip_buffer_offset(buffer)) < 0) {
  ------------------
  |  Branch (186:9): [True: 0, False: 490]
  ------------------
  187|      0|        _zip_buffer_free(buffer);
  188|      0|        return -1;
  189|      0|    }
  190|       |
  191|    490|    _zip_buffer_free(buffer);
  192|       |
  193|    490|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
  194|      0|        char torrentzip_comment[TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH + 1];
  195|      0|        snprintf(torrentzip_comment, sizeof(torrentzip_comment), TORRENTZIP_SIGNATURE "%08X", cdir_crc);
  ------------------
  |  |   71|      0|#define TORRENTZIP_SIGNATURE "TORRENTZIPPED-"
  ------------------
  196|       |
  197|      0|        if (_zip_write(za, torrentzip_comment, strlen(torrentzip_comment)) < 0) {
  ------------------
  |  Branch (197:13): [True: 0, False: 0]
  ------------------
  198|      0|            return -1;
  199|      0|        }
  200|      0|    }
  201|    490|    else if (comment != NULL) {
  ------------------
  |  Branch (201:14): [True: 0, False: 490]
  ------------------
  202|      0|        if (_zip_write(za, comment->raw, comment->length) < 0) {
  ------------------
  |  Branch (202:13): [True: 0, False: 0]
  ------------------
  203|      0|            return -1;
  204|      0|        }
  205|      0|    }
  206|       |
  207|    490|    return (zip_int64_t)size;
  208|    490|}
_zip_dirent_clone:
  211|    490|zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *sde) {
  212|    490|    zip_dirent_t *tde;
  213|       |
  214|    490|    if ((tde = (zip_dirent_t *)malloc(sizeof(*tde))) == NULL) {
  ------------------
  |  Branch (214:9): [True: 0, False: 490]
  ------------------
  215|      0|        return NULL;
  216|      0|    }
  217|       |
  218|    490|    if (sde) {
  ------------------
  |  Branch (218:9): [True: 0, False: 490]
  ------------------
  219|      0|        (void)memcpy_s(tde, sizeof(*tde), sde, sizeof(*sde));
  ------------------
  |  |  200|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  220|      0|    }
  221|    490|    else {
  222|    490|        _zip_dirent_init(tde);
  223|    490|    }
  224|       |
  225|    490|    tde->changed = 0;
  226|    490|    tde->cloned = 1;
  227|       |
  228|    490|    return tde;
  229|    490|}
_zip_dirent_finalize:
  232|    490|void _zip_dirent_finalize(zip_dirent_t *zde) {
  233|    490|    if (!zde->cloned || zde->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  334|    490|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (233:9): [True: 0, False: 490]
  |  Branch (233:25): [True: 490, False: 0]
  ------------------
  234|    490|        _zip_string_free(zde->filename);
  235|    490|        zde->filename = NULL;
  236|    490|    }
  237|    490|    if (!zde->cloned || zde->changed & ZIP_DIRENT_EXTRA_FIELD) {
  ------------------
  |  |  336|    490|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  |  Branch (237:9): [True: 0, False: 490]
  |  Branch (237:25): [True: 490, False: 0]
  ------------------
  238|    490|        _zip_ef_free(zde->extra_fields);
  239|    490|        zde->extra_fields = NULL;
  240|    490|    }
  241|    490|    if (!zde->cloned || zde->changed & ZIP_DIRENT_COMMENT) {
  ------------------
  |  |  335|    490|#define ZIP_DIRENT_COMMENT 0x0004u
  ------------------
  |  Branch (241:9): [True: 0, False: 490]
  |  Branch (241:25): [True: 0, False: 490]
  ------------------
  242|      0|        _zip_string_free(zde->comment);
  243|      0|        zde->comment = NULL;
  244|      0|    }
  245|    490|    if (!zde->cloned || zde->changed & ZIP_DIRENT_PASSWORD) {
  ------------------
  |  |  340|    490|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (245:9): [True: 0, False: 490]
  |  Branch (245:25): [True: 490, False: 0]
  ------------------
  246|    490|        if (zde->password) {
  ------------------
  |  Branch (246:13): [True: 490, False: 0]
  ------------------
  247|    490|            _zip_crypto_clear(zde->password, strlen(zde->password));
  ------------------
  |  |  521|    490|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  248|    490|        }
  249|    490|        free(zde->password);
  250|       |        zde->password = NULL;
  251|    490|    }
  252|    490|}
_zip_dirent_free:
  255|    980|void _zip_dirent_free(zip_dirent_t *zde) {
  256|    980|    if (zde == NULL) {
  ------------------
  |  Branch (256:9): [True: 490, False: 490]
  ------------------
  257|    490|        return;
  258|    490|    }
  259|       |
  260|    490|    _zip_dirent_finalize(zde);
  261|    490|    free(zde);
  262|    490|}
_zip_dirent_init:
  313|    490|void _zip_dirent_init(zip_dirent_t *de) {
  314|    490|    de->changed = 0;
  315|    490|    de->local_extra_fields_read = 0;
  316|    490|    de->cloned = 0;
  317|       |
  318|    490|    de->crc_valid = true;
  319|    490|    de->last_mod_mtime_valid = false;
  320|    490|    de->version_madeby = 63 | (ZIP_OPSYS_DEFAULT << 8);
  ------------------
  |  |  246|    490|#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
  |  |  ------------------
  |  |  |  |  228|    490|#define ZIP_OPSYS_UNIX 0x03u
  |  |  ------------------
  ------------------
  321|    490|    de->version_needed = 10; /* 1.0 */
  322|    490|    de->bitflags = 0;
  323|    490|    de->comp_method = ZIP_CM_DEFAULT;
  ------------------
  |  |  178|    490|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  324|    490|    de->last_mod.date = 0;
  325|    490|    de->last_mod.time = 0;
  326|    490|    de->crc = 0;
  327|    490|    de->comp_size = 0;
  328|    490|    de->uncomp_size = 0;
  329|    490|    de->filename = NULL;
  330|    490|    de->extra_fields = NULL;
  331|    490|    de->comment = NULL;
  332|    490|    de->disk_number = 0;
  333|    490|    de->int_attrib = 0;
  334|    490|    de->ext_attrib = ZIP_EXT_ATTRIB_DEFAULT;
  ------------------
  |  |   97|    490|#define ZIP_EXT_ATTRIB_DEFAULT (0100666u << 16)
  ------------------
  335|    490|    de->offset = 0;
  336|    490|    de->compression_level = 0;
  337|    490|    de->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|    490|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  338|       |    de->password = NULL;
  339|    490|}
_zip_dirent_needs_zip64:
  342|  2.45k|bool _zip_dirent_needs_zip64(const zip_dirent_t *de, zip_flags_t flags) {
  343|  2.45k|    if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |   42|  4.90k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |   42|  4.90k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |  105|  2.45k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
                  if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |   42|    490|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (343:9): [True: 0, False: 2.45k]
  |  Branch (343:46): [True: 0, False: 2.45k]
  |  Branch (343:82): [True: 490, False: 1.96k]
  |  Branch (343:110): [True: 0, False: 490]
  ------------------
  344|      0|        return true;
  345|      0|    }
  346|       |
  347|  2.45k|    return false;
  348|  2.45k|}
_zip_dirent_write:
  880|  1.47k|int _zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) {
  881|  1.47k|    zip_dostime_t dostime;
  882|  1.47k|    zip_encoding_type_t com_enc, name_enc;
  883|  1.47k|    zip_extra_field_t *ef;
  884|  1.47k|    zip_extra_field_t *ef64;
  885|  1.47k|    zip_uint32_t ef_total_size;
  886|  1.47k|    bool is_zip64;
  887|  1.47k|    bool is_really_zip64;
  888|  1.47k|    bool is_winzip_aes;
  889|  1.47k|    zip_uint8_t buf[CDENTRYSIZE];
  890|  1.47k|    zip_buffer_t *buffer;
  891|       |
  892|  1.47k|    ef = NULL;
  893|       |
  894|  1.47k|    name_enc = _zip_guess_encoding(de->filename, ZIP_ENCODING_UNKNOWN);
  895|  1.47k|    com_enc = _zip_guess_encoding(de->comment, ZIP_ENCODING_UNKNOWN);
  896|       |
  897|  1.47k|    if ((name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_ASCII) || (name_enc == ZIP_ENCODING_ASCII && com_enc == ZIP_ENCODING_UTF8_KNOWN) || (name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_UTF8_KNOWN)) {
  ------------------
  |  Branch (897:10): [True: 0, False: 1.47k]
  |  Branch (897:49): [True: 0, False: 0]
  |  Branch (897:84): [True: 1.47k, False: 0]
  |  Branch (897:118): [True: 0, False: 1.47k]
  |  Branch (897:158): [True: 0, False: 1.47k]
  |  Branch (897:197): [True: 0, False: 0]
  ------------------
  898|      0|        de->bitflags |= ZIP_GPBF_ENCODING_UTF_8;
  ------------------
  |  |  254|      0|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  899|      0|    }
  900|  1.47k|    else {
  901|  1.47k|        de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCODING_UTF_8;
  ------------------
  |  |  254|  1.47k|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  902|  1.47k|        if (name_enc == ZIP_ENCODING_UTF8_KNOWN) {
  ------------------
  |  Branch (902:13): [True: 0, False: 1.47k]
  ------------------
  903|      0|            ef = _zip_ef_utf8(ZIP_EF_UTF_8_NAME, de->filename, &za->error);
  ------------------
  |  |   90|      0|#define ZIP_EF_UTF_8_NAME 0x7075
  ------------------
  904|      0|            if (ef == NULL) {
  ------------------
  |  Branch (904:17): [True: 0, False: 0]
  ------------------
  905|      0|                return -1;
  906|      0|            }
  907|      0|        }
  908|  1.47k|        if ((flags & ZIP_FL_LOCAL) == 0 && com_enc == ZIP_ENCODING_UTF8_KNOWN) {
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (908:13): [True: 490, False: 980]
  |  Branch (908:44): [True: 0, False: 490]
  ------------------
  909|      0|            zip_extra_field_t *ef2 = _zip_ef_utf8(ZIP_EF_UTF_8_COMMENT, de->comment, &za->error);
  ------------------
  |  |   89|      0|#define ZIP_EF_UTF_8_COMMENT 0x6375
  ------------------
  910|      0|            if (ef2 == NULL) {
  ------------------
  |  Branch (910:17): [True: 0, False: 0]
  ------------------
  911|      0|                _zip_ef_free(ef);
  912|      0|                return -1;
  913|      0|            }
  914|      0|            ef2->next = ef;
  915|      0|            ef = ef2;
  916|      0|        }
  917|  1.47k|    }
  918|       |
  919|  1.47k|    if (de->encryption_method == ZIP_EM_NONE) {
  ------------------
  |  |  207|  1.47k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (919:9): [True: 0, False: 1.47k]
  ------------------
  920|      0|        de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCRYPTED;
  ------------------
  |  |  251|      0|#define ZIP_GPBF_ENCRYPTED 0x0001u         /* is encrypted */
  ------------------
  921|      0|    }
  922|  1.47k|    else {
  923|  1.47k|        de->bitflags |= (zip_uint16_t)ZIP_GPBF_ENCRYPTED;
  ------------------
  |  |  251|  1.47k|#define ZIP_GPBF_ENCRYPTED 0x0001u         /* is encrypted */
  ------------------
  924|  1.47k|    }
  925|       |
  926|  1.47k|    is_really_zip64 = _zip_dirent_needs_zip64(de, flags);
  927|  1.47k|    is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  262|  1.47k|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
                  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  262|  1.47k|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  |  Branch (927:16): [True: 0, False: 1.47k]
  |  Branch (927:104): [True: 0, False: 1.47k]
  ------------------
  928|  1.47k|    is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
  ------------------
  |  |  220|  2.94k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
                  is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
  ------------------
  |  |  221|  2.94k|#define ZIP_EM_AES_192 0x0102
  ------------------
                  is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
  ------------------
  |  |  222|  2.94k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (928:21): [True: 0, False: 1.47k]
  |  Branch (928:64): [True: 0, False: 1.47k]
  |  Branch (928:107): [True: 0, False: 1.47k]
  ------------------
  929|       |
  930|  1.47k|    if (is_zip64) {
  ------------------
  |  Branch (930:9): [True: 0, False: 1.47k]
  ------------------
  931|      0|        zip_uint8_t ef_zip64[EFZIP64SIZE];
  932|      0|        zip_buffer_t *ef_buffer = _zip_buffer_new(ef_zip64, sizeof(ef_zip64));
  933|      0|        if (ef_buffer == NULL) {
  ------------------
  |  Branch (933:13): [True: 0, False: 0]
  ------------------
  934|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  935|      0|            _zip_ef_free(ef);
  936|      0|            return -1;
  937|      0|        }
  938|       |
  939|      0|        if (flags & ZIP_FL_LOCAL) {
  ------------------
  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (939:13): [True: 0, False: 0]
  ------------------
  940|      0|            if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
  ------------------
  |  |  262|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (940:17): [True: 0, False: 0]
  |  Branch (940:49): [True: 0, False: 0]
  |  Branch (940:83): [True: 0, False: 0]
  ------------------
  941|      0|                _zip_buffer_put_64(ef_buffer, de->uncomp_size);
  942|      0|                _zip_buffer_put_64(ef_buffer, de->comp_size);
  943|      0|            }
  944|      0|        }
  945|      0|        else {
  946|      0|            if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |  262|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (946:17): [True: 0, False: 0]
  |  Branch (946:49): [True: 0, False: 0]
  |  Branch (946:83): [True: 0, False: 0]
  |  Branch (946:119): [True: 0, False: 0]
  ------------------
  947|      0|                if (de->uncomp_size >= ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (947:21): [True: 0, False: 0]
  ------------------
  948|      0|                    _zip_buffer_put_64(ef_buffer, de->uncomp_size);
  949|      0|                }
  950|      0|                if (de->comp_size >= ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (950:21): [True: 0, False: 0]
  ------------------
  951|      0|                    _zip_buffer_put_64(ef_buffer, de->comp_size);
  952|      0|                }
  953|      0|                if (de->offset >= ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (953:21): [True: 0, False: 0]
  ------------------
  954|      0|                    _zip_buffer_put_64(ef_buffer, de->offset);
  955|      0|                }
  956|      0|            }
  957|      0|        }
  958|       |
  959|      0|        if (!_zip_buffer_ok(ef_buffer)) {
  ------------------
  |  Branch (959:13): [True: 0, False: 0]
  ------------------
  960|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  961|      0|            _zip_buffer_free(ef_buffer);
  962|      0|            _zip_ef_free(ef);
  963|      0|            return -1;
  964|      0|        }
  965|       |
  966|      0|        ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
  ------------------
  |  |   92|      0|#define ZIP_EF_ZIP64 0x0001
  ------------------
                      ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  967|      0|        _zip_buffer_free(ef_buffer);
  968|      0|        if (ef64 == NULL) {
  ------------------
  |  Branch (968:13): [True: 0, False: 0]
  ------------------
  969|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  970|      0|            _zip_ef_free(ef);
  971|      0|            return -1;
  972|      0|        }
  973|      0|        ef64->next = ef;
  974|      0|        ef = ef64;
  975|      0|    }
  976|       |
  977|  1.47k|    if (is_winzip_aes) {
  ------------------
  |  Branch (977:9): [True: 0, False: 1.47k]
  ------------------
  978|      0|        zip_uint8_t data[EF_WINZIP_AES_SIZE];
  979|      0|        zip_buffer_t *ef_buffer = _zip_buffer_new(data, sizeof(data));
  980|      0|        zip_extra_field_t *ef_winzip;
  981|       |
  982|      0|        if (ef_buffer == NULL) {
  ------------------
  |  Branch (982:13): [True: 0, False: 0]
  ------------------
  983|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  984|      0|            _zip_ef_free(ef);
  985|      0|            return -1;
  986|      0|        }
  987|       |
  988|      0|        _zip_buffer_put_16(ef_buffer, 2);
  989|      0|        _zip_buffer_put(ef_buffer, "AE", 2);
  990|      0|        _zip_buffer_put_8(ef_buffer, (zip_uint8_t)(de->encryption_method & 0xff));
  991|      0|        _zip_buffer_put_16(ef_buffer, (zip_uint16_t)de->comp_method);
  992|       |
  993|      0|        if (!_zip_buffer_ok(ef_buffer)) {
  ------------------
  |  Branch (993:13): [True: 0, False: 0]
  ------------------
  994|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  995|      0|            _zip_buffer_free(ef_buffer);
  996|      0|            _zip_ef_free(ef);
  997|      0|            return -1;
  998|      0|        }
  999|       |
 1000|      0|        ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data, ZIP_EF_BOTH);
  ------------------
  |  |   91|      0|#define ZIP_EF_WINZIP_AES 0x9901
  ------------------
                      ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data, ZIP_EF_BOTH);
  ------------------
  |  |   68|      0|#define EF_WINZIP_AES_SIZE 7
  ------------------
                      ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data, ZIP_EF_BOTH);
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1001|      0|        _zip_buffer_free(ef_buffer);
 1002|      0|        if (ef_winzip == NULL) {
  ------------------
  |  Branch (1002:13): [True: 0, False: 0]
  ------------------
 1003|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
 1004|      0|            _zip_ef_free(ef);
 1005|      0|            return -1;
 1006|      0|        }
 1007|      0|        ef_winzip->next = ef;
 1008|      0|        ef = ef_winzip;
 1009|      0|    }
 1010|       |
 1011|  1.47k|    if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
  ------------------
  |  Branch (1011:9): [True: 0, False: 1.47k]
  ------------------
 1012|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
 1013|      0|        _zip_ef_free(ef);
 1014|      0|        return -1;
 1015|      0|    }
 1016|       |
 1017|  1.47k|    _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
  ------------------
  |  |   52|    980|#define LOCAL_MAGIC "PK\3\4"
  ------------------
                  _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
  ------------------
  |  |   51|  1.96k|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (1017:29): [True: 980, False: 490]
  ------------------
 1018|       |
 1019|  1.47k|    if ((flags & ZIP_FL_LOCAL) == 0) {
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (1019:9): [True: 490, False: 980]
  ------------------
 1020|    490|        _zip_buffer_put_16(buffer, de->version_madeby);
 1021|    490|    }
 1022|  1.47k|    _zip_buffer_put_16(buffer, ZIP_MAX(is_really_zip64 ? 45 : 0, de->version_needed));
  ------------------
  |  |  502|  2.94k|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (502:24): [True: 0, False: 1.47k]
  |  |  |  Branch (502:25): [True: 0, False: 1.47k]
  |  |  |  Branch (502:37): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1023|  1.47k|    _zip_buffer_put_16(buffer, de->bitflags);
 1024|  1.47k|    if (is_winzip_aes) {
  ------------------
  |  Branch (1024:9): [True: 0, False: 1.47k]
  ------------------
 1025|      0|        _zip_buffer_put_16(buffer, ZIP_CM_WINZIP_AES);
  ------------------
  |  |   79|      0|#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
  ------------------
 1026|      0|    }
 1027|  1.47k|    else {
 1028|  1.47k|        _zip_buffer_put_16(buffer, (zip_uint16_t)ZIP_CM_ACTUAL(de->comp_method));
  ------------------
  |  |   87|  1.47k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  1.47k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    490|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 490, False: 980]
  |  |  ------------------
  ------------------
 1029|  1.47k|    }
 1030|       |
 1031|  1.47k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|  1.47k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  1.47k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 1.47k]
  |  |  ------------------
  ------------------
 1032|      0|        dostime.time = 0xbc00;
 1033|      0|        dostime.date = 0x2198;
 1034|      0|    }
 1035|  1.47k|    else {
 1036|  1.47k|        dostime = de->last_mod;
 1037|  1.47k|    }
 1038|  1.47k|    _zip_buffer_put_16(buffer, dostime.time);
 1039|  1.47k|    _zip_buffer_put_16(buffer, dostime.date);
 1040|       |
 1041|  1.47k|    if (is_winzip_aes && de->uncomp_size < 20) {
  ------------------
  |  Branch (1041:9): [True: 0, False: 1.47k]
  |  Branch (1041:26): [True: 0, False: 0]
  ------------------
 1042|      0|        _zip_buffer_put_32(buffer, 0);
 1043|      0|    }
 1044|  1.47k|    else {
 1045|  1.47k|        _zip_buffer_put_32(buffer, de->crc);
 1046|  1.47k|    }
 1047|       |
 1048|  1.47k|    if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |   42|    980|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |   42|    980|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1048:9): [True: 980, False: 490]
  |  Branch (1048:54): [True: 0, False: 980]
  |  Branch (1048:91): [True: 0, False: 980]
  ------------------
 1049|       |        /* In local headers, if a ZIP64 EF is written, it MUST contain
 1050|       |         * both compressed and uncompressed sizes (even if one of the
 1051|       |         * two is smaller than 0xFFFFFFFF); on the other hand, those
 1052|       |         * may only appear when the corresponding standard entry is
 1053|       |         * 0xFFFFFFFF.  (appnote.txt 4.5.3) */
 1054|      0|        _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1055|      0|        _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1056|      0|    }
 1057|  1.47k|    else {
 1058|  1.47k|        if (de->comp_size < ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  1.47k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1058:13): [True: 1.47k, False: 0]
  ------------------
 1059|  1.47k|            _zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size);
 1060|  1.47k|        }
 1061|      0|        else {
 1062|      0|            _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1063|      0|        }
 1064|  1.47k|        if (de->uncomp_size < ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  1.47k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1064:13): [True: 1.47k, False: 0]
  ------------------
 1065|  1.47k|            _zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size);
 1066|  1.47k|        }
 1067|      0|        else {
 1068|      0|            _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1069|      0|        }
 1070|  1.47k|    }
 1071|       |
 1072|  1.47k|    _zip_buffer_put_16(buffer, _zip_string_length(de->filename));
 1073|  1.47k|    ef_total_size = _zip_ef_size(ef, ZIP_EF_BOTH);
  ------------------
  |  |  260|  1.47k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|  1.47k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|  1.47k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  1.47k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1074|  1.47k|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|  1.47k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  1.47k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (1074:9): [True: 1.47k, False: 0]
  ------------------
 1075|       |        /* TODO: check for overflow */
 1076|  1.47k|        ef_total_size += _zip_ef_size(de->extra_fields, flags);
 1077|  1.47k|    }
 1078|  1.47k|    if (ef_total_size > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  1.47k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (1078:9): [True: 0, False: 1.47k]
  ------------------
 1079|      0|        zip_error_set(&za->error, ZIP_ER_EF_TOO_LARGE, 0);
  ------------------
  |  |  167|      0|#define ZIP_ER_EF_TOO_LARGE 36    /* N Extra fields too large */
  ------------------
 1080|      0|        _zip_buffer_free(buffer);
 1081|      0|        _zip_ef_free(ef);
 1082|      0|        return -1;
 1083|      0|    }
 1084|  1.47k|    _zip_buffer_put_16(buffer, (zip_uint16_t)ef_total_size);
 1085|       |
 1086|  1.47k|    if ((flags & ZIP_FL_LOCAL) == 0) {
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (1086:9): [True: 490, False: 980]
  ------------------
 1087|    490|        _zip_buffer_put_16(buffer, ZIP_WANT_TORRENTZIP(za) ? 0 : _zip_string_length(de->comment));
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
 1088|    490|        _zip_buffer_put_16(buffer, (zip_uint16_t)de->disk_number);
 1089|    490|        _zip_buffer_put_16(buffer, de->int_attrib);
 1090|    490|        _zip_buffer_put_32(buffer, de->ext_attrib);
 1091|    490|        if (de->offset < ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    490|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1091:13): [True: 490, False: 0]
  ------------------
 1092|    490|            _zip_buffer_put_32(buffer, (zip_uint32_t)de->offset);
 1093|    490|        }
 1094|      0|        else {
 1095|      0|            _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1096|      0|        }
 1097|    490|    }
 1098|       |
 1099|  1.47k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 1.47k]
  ------------------
 1100|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
 1101|      0|        _zip_buffer_free(buffer);
 1102|      0|        _zip_ef_free(ef);
 1103|      0|        return -1;
 1104|      0|    }
 1105|       |
 1106|  1.47k|    if (_zip_write(za, buf, _zip_buffer_offset(buffer)) < 0) {
  ------------------
  |  Branch (1106:9): [True: 0, False: 1.47k]
  ------------------
 1107|      0|        _zip_buffer_free(buffer);
 1108|      0|        _zip_ef_free(ef);
 1109|      0|        return -1;
 1110|      0|    }
 1111|       |
 1112|  1.47k|    _zip_buffer_free(buffer);
 1113|       |
 1114|  1.47k|    if (de->filename) {
  ------------------
  |  Branch (1114:9): [True: 1.47k, False: 0]
  ------------------
 1115|  1.47k|        if (_zip_string_write(za, de->filename) < 0) {
  ------------------
  |  Branch (1115:13): [True: 0, False: 1.47k]
  ------------------
 1116|      0|            _zip_ef_free(ef);
 1117|      0|            return -1;
 1118|      0|        }
 1119|  1.47k|    }
 1120|       |
 1121|  1.47k|    if (ef) {
  ------------------
  |  Branch (1121:9): [True: 0, False: 1.47k]
  ------------------
 1122|      0|        if (_zip_ef_write(za, ef, ZIP_EF_BOTH) < 0) {
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1122:13): [True: 0, False: 0]
  ------------------
 1123|      0|            _zip_ef_free(ef);
 1124|      0|            return -1;
 1125|      0|        }
 1126|      0|    }
 1127|  1.47k|    _zip_ef_free(ef);
 1128|  1.47k|    if (de->extra_fields && !ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|      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 (1128:9): [True: 0, False: 1.47k]
  |  Branch (1128:29): [True: 0, False: 0]
  ------------------
 1129|      0|        if (_zip_ef_write(za, de->extra_fields, flags) < 0) {
  ------------------
  |  Branch (1129:13): [True: 0, False: 0]
  ------------------
 1130|      0|            return -1;
 1131|      0|        }
 1132|      0|    }
 1133|       |
 1134|  1.47k|    if ((flags & ZIP_FL_LOCAL) == 0 && !ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  104|  1.47k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  if ((flags & ZIP_FL_LOCAL) == 0 && !ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (1134:9): [True: 490, False: 980]
  |  Branch (1134:40): [True: 490, False: 0]
  ------------------
 1135|    490|        if (de->comment) {
  ------------------
  |  Branch (1135:13): [True: 0, False: 490]
  ------------------
 1136|      0|            if (_zip_string_write(za, de->comment) < 0) {
  ------------------
  |  Branch (1136:17): [True: 0, False: 0]
  ------------------
 1137|      0|                return -1;
 1138|      0|            }
 1139|      0|        }
 1140|    490|    }
 1141|       |
 1142|       |
 1143|  1.47k|    return is_zip64;
 1144|  1.47k|}
_zip_get_dirent:
 1205|    980|zip_dirent_t *_zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
 1206|    980|    if (error == NULL) {
  ------------------
  |  Branch (1206:9): [True: 490, False: 490]
  ------------------
 1207|    490|        error = &za->error;
 1208|    490|    }
 1209|       |
 1210|    980|    if (idx >= za->nentry) {
  ------------------
  |  Branch (1210:9): [True: 0, False: 980]
  ------------------
 1211|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1212|      0|        return NULL;
 1213|      0|    }
 1214|       |
 1215|    980|    if ((flags & ZIP_FL_UNCHANGED) || za->entry[idx].changes == NULL) {
  ------------------
  |  |   98|    980|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (1215:9): [True: 0, False: 980]
  |  Branch (1215:39): [True: 0, False: 980]
  ------------------
 1216|      0|        if (za->entry[idx].orig == NULL) {
  ------------------
  |  Branch (1216:13): [True: 0, False: 0]
  ------------------
 1217|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1218|      0|            return NULL;
 1219|      0|        }
 1220|      0|        if (za->entry[idx].deleted && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (1220:13): [True: 0, False: 0]
  |  Branch (1220:39): [True: 0, False: 0]
  ------------------
 1221|      0|            zip_error_set(error, ZIP_ER_DELETED, 0);
  ------------------
  |  |  154|      0|#define ZIP_ER_DELETED 23         /* N Entry has been deleted */
  ------------------
 1222|      0|            return NULL;
 1223|      0|        }
 1224|      0|        return za->entry[idx].orig;
 1225|      0|    }
 1226|    980|    else {
 1227|    980|        return za->entry[idx].changes;
 1228|    980|    }
 1229|    980|}
_zip_u2d_time:
 1232|    980|int _zip_u2d_time(time_t intime, zip_dostime_t *dtime, zip_error_t *ze) {
 1233|    980|    struct tm *tpm;
 1234|    980|    struct tm tm;
 1235|    980|    tpm = zip_localtime(&intime, &tm);
  ------------------
  |  |  193|    980|#define zip_localtime localtime_r
  ------------------
 1236|    980|    if (tpm == NULL) {
  ------------------
  |  Branch (1236:9): [True: 0, False: 980]
  ------------------
 1237|       |        /* if localtime fails, return an arbitrary date (1980-01-01 00:00:00) */
 1238|      0|        dtime->date = (1 << 5) + 1;
 1239|      0|        dtime->time = 0;
 1240|      0|        if (ze) {
  ------------------
  |  Branch (1240:13): [True: 0, False: 0]
  ------------------
 1241|      0|            zip_error_set(ze, ZIP_ER_INVAL, errno);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1242|      0|        }
 1243|      0|        return -1;
 1244|      0|    }
 1245|    980|    if (tpm->tm_year < 80) {
  ------------------
  |  Branch (1245:9): [True: 0, False: 980]
  ------------------
 1246|      0|        tpm->tm_year = 80;
 1247|      0|    }
 1248|       |
 1249|    980|    dtime->date = (zip_uint16_t)(((tpm->tm_year + 1900 - 1980) << 9) + ((tpm->tm_mon + 1) << 5) + tpm->tm_mday);
 1250|    980|    dtime->time = (zip_uint16_t)(((tpm->tm_hour) << 11) + ((tpm->tm_min) << 5) + ((tpm->tm_sec) >> 1));
 1251|       |
 1252|    980|    return 0;
 1253|    980|}
_zip_dirent_apply_attributes:
 1256|    980|bool _zip_dirent_apply_attributes(zip_dirent_t *de, zip_file_attributes_t *attributes, bool force_zip64) {
 1257|    980|    zip_uint16_t length;
 1258|    980|    bool has_changed = false;
 1259|    980|    zip_uint16_t version_madeby, version_needed;
 1260|       |
 1261|    980|    if (attributes->valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS) {
  ------------------
  |  |  365|    980|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  |  Branch (1261:9): [True: 980, False: 0]
  ------------------
 1262|    980|        zip_uint16_t mask = attributes->general_purpose_bit_mask & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK;
  ------------------
  |  |  102|    980|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK 0x083e
  ------------------
 1263|    980|        zip_uint16_t bitflags = (de->bitflags & ~mask) | (attributes->general_purpose_bit_flags & mask);
 1264|    980|        if (de->bitflags != bitflags) {
  ------------------
  |  Branch (1264:13): [True: 621, False: 359]
  ------------------
 1265|    621|            de->bitflags = bitflags;
 1266|    621|            has_changed = true;
 1267|    621|        }
 1268|    980|    }
 1269|    980|    if (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) {
  ------------------
  |  |  362|    980|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
  |  Branch (1269:9): [True: 0, False: 980]
  ------------------
 1270|      0|        zip_uint16_t int_attrib = (de->int_attrib & ~0x1) | (attributes->ascii ? 1 : 0);
  ------------------
  |  Branch (1270:62): [True: 0, False: 0]
  ------------------
 1271|      0|        if (de->int_attrib != int_attrib) {
  ------------------
  |  Branch (1271:13): [True: 0, False: 0]
  ------------------
 1272|      0|            de->int_attrib = int_attrib;
 1273|      0|            has_changed = true;
 1274|      0|        }
 1275|      0|    }
 1276|       |    /* manually set attributes are preferred over attributes provided by source */
 1277|    980|    if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES)) {
  ------------------
  |  |  337|    980|#define ZIP_DIRENT_ATTRIBUTES 0x0010u
  ------------------
                  if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES)) {
  ------------------
  |  |  364|    980|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
  |  Branch (1277:9): [True: 980, False: 0]
  |  Branch (1277:55): [True: 0, False: 980]
  ------------------
 1278|      0|        if (de->ext_attrib != attributes->external_file_attributes) {
  ------------------
  |  Branch (1278:13): [True: 0, False: 0]
  ------------------
 1279|      0|            de->ext_attrib = attributes->external_file_attributes;
 1280|      0|            has_changed = true;
 1281|      0|        }
 1282|      0|    }
 1283|       |
 1284|    980|    if (de->comp_method == ZIP_CM_LZMA) {
  ------------------
  |  |  193|    980|#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
  ------------------
  |  Branch (1284:9): [True: 0, False: 980]
  ------------------
 1285|      0|        version_needed = 63;
 1286|      0|    }
 1287|    980|    else if (de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256) {
  ------------------
  |  |  220|  1.96k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
                  else if (de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256) {
  ------------------
  |  |  221|  1.96k|#define ZIP_EM_AES_192 0x0102
  ------------------
                  else if (de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256) {
  ------------------
  |  |  222|    980|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (1287:14): [True: 0, False: 980]
  |  Branch (1287:57): [True: 0, False: 980]
  |  Branch (1287:100): [True: 0, False: 980]
  ------------------
 1288|      0|        version_needed = 51;
 1289|      0|    }
 1290|    980|    else if (de->comp_method == ZIP_CM_BZIP2) {
  ------------------
  |  |  191|    980|#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
  ------------------
  |  Branch (1290:14): [True: 0, False: 980]
  ------------------
 1291|      0|        version_needed = 46;
 1292|      0|    }
 1293|    980|    else if (force_zip64 || _zip_dirent_needs_zip64(de, 0)) {
  ------------------
  |  Branch (1293:14): [True: 0, False: 980]
  |  Branch (1293:29): [True: 0, False: 980]
  ------------------
 1294|      0|        version_needed = 45;
 1295|      0|    }
 1296|    980|    else if (de->comp_method == ZIP_CM_DEFLATE || de->encryption_method == ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  187|  1.96k|#define ZIP_CM_DEFLATE 8         /* deflated */
  ------------------
                  else if (de->comp_method == ZIP_CM_DEFLATE || de->encryption_method == ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|    621|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (1296:14): [True: 359, False: 621]
  |  Branch (1296:51): [True: 621, False: 0]
  ------------------
 1297|    980|        version_needed = 20;
 1298|    980|    }
 1299|      0|    else if ((length = _zip_string_length(de->filename)) > 0 && de->filename->raw[length - 1] == '/') {
  ------------------
  |  Branch (1299:14): [True: 0, False: 0]
  |  Branch (1299:65): [True: 0, False: 0]
  ------------------
 1300|      0|        version_needed = 20;
 1301|      0|    }
 1302|      0|    else {
 1303|      0|        version_needed = 10;
 1304|      0|    }
 1305|       |
 1306|    980|    if (attributes->valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED) {
  ------------------
  |  |  363|    980|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  |  Branch (1306:9): [True: 980, False: 0]
  ------------------
 1307|    980|        version_needed = ZIP_MAX(version_needed, attributes->version_needed);
  ------------------
  |  |  502|    980|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (502:24): [True: 0, False: 980]
  |  |  ------------------
  ------------------
 1308|    980|    }
 1309|       |
 1310|    980|    if (de->version_needed != version_needed) {
  ------------------
  |  Branch (1310:9): [True: 490, False: 490]
  ------------------
 1311|    490|        de->version_needed = version_needed;
 1312|    490|        has_changed = true;
 1313|    490|    }
 1314|       |
 1315|    980|    version_madeby = 63 | (de->version_madeby & 0xff00);
 1316|    980|    if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM)) {
  ------------------
  |  |  337|    980|#define ZIP_DIRENT_ATTRIBUTES 0x0010u
  ------------------
                  if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM)) {
  ------------------
  |  |  361|    980|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
  |  Branch (1316:9): [True: 980, False: 0]
  |  Branch (1316:55): [True: 0, False: 980]
  ------------------
 1317|      0|        version_madeby = (version_madeby & 0xff) | (zip_uint16_t)(attributes->host_system << 8);
 1318|      0|    }
 1319|    980|    if (de->version_madeby != version_madeby) {
  ------------------
  |  Branch (1319:9): [True: 0, False: 980]
  ------------------
 1320|      0|        de->version_madeby = version_madeby;
 1321|      0|        has_changed = true;
 1322|      0|    }
 1323|       |
 1324|    980|    return has_changed;
 1325|    980|}

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

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

zip_error_code_system:
   39|  1.47k|ZIP_EXTERN int zip_error_code_system(const zip_error_t *error) {
   40|  1.47k|    return error->sys_err;
   41|  1.47k|}
zip_error_code_zip:
   44|  13.2k|ZIP_EXTERN int zip_error_code_zip(const zip_error_t *error) {
   45|  13.2k|    return error->zip_err;
   46|  13.2k|}
zip_error_fini:
   49|  1.96k|ZIP_EXTERN void zip_error_fini(zip_error_t *err) {
   50|  1.96k|    free(err->str);
   51|       |    err->str = NULL;
   52|  1.96k|}
zip_error_init:
   55|  6.37k|ZIP_EXTERN void zip_error_init(zip_error_t *err) {
   56|  6.37k|    err->zip_err = ZIP_ER_OK;
  ------------------
  |  |  131|  6.37k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   57|  6.37k|    err->sys_err = 0;
   58|       |    err->str = NULL;
   59|  6.37k|}
_zip_error_clear:
   86|  1.96k|void _zip_error_clear(zip_error_t *err) {
   87|  1.96k|    if (err == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 1.96k]
  ------------------
   88|      0|        return;
   89|      0|    }
   90|       |
   91|  1.96k|    err->zip_err = ZIP_ER_OK;
  ------------------
  |  |  131|  1.96k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   92|  1.96k|    err->sys_err = 0;
   93|  1.96k|}
zip_error_set:
  121|  2.94k|void zip_error_set(zip_error_t *err, int ze, int se) {
  122|  2.94k|    if (err) {
  ------------------
  |  Branch (122:9): [True: 1.96k, False: 980]
  ------------------
  123|  1.96k|        err->zip_err = ze;
  124|  1.96k|        err->sys_err = se;
  125|  1.96k|    }
  126|  2.94k|}
zip_error_to_data:
  139|    490|zip_int64_t zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) {
  140|    490|    int *e = (int *)data;
  141|       |
  142|    490|    if (length < sizeof(int) * 2) {
  ------------------
  |  Branch (142:9): [True: 0, False: 490]
  ------------------
  143|      0|        return -1;
  144|      0|    }
  145|       |
  146|    490|    e[0] = zip_error_code_zip(error);
  147|    490|    e[1] = zip_error_code_system(error);
  148|    490|    return sizeof(int) * 2;
  149|    490|}

_zip_ef_delete_by_id:
   67|    490|zip_extra_field_t *_zip_ef_delete_by_id(zip_extra_field_t *ef, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags) {
   68|    490|    zip_extra_field_t *head, *prev;
   69|    490|    int i;
   70|       |
   71|    490|    i = 0;
   72|    490|    head = ef;
   73|    490|    prev = NULL;
   74|    490|    for (; ef; ef = (prev ? prev->next : head)) {
  ------------------
  |  Branch (74:12): [True: 0, False: 490]
  |  Branch (74:22): [True: 0, False: 0]
  ------------------
   75|      0|        if ((ef->flags & flags & ZIP_EF_BOTH) && ((ef->id == id) || (id == ZIP_EXTRA_FIELD_ALL))) {
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      if ((ef->flags & flags & ZIP_EF_BOTH) && ((ef->id == id) || (id == ZIP_EXTRA_FIELD_ALL))) {
  ------------------
  |  |  121|      0|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (75:13): [True: 0, False: 0]
  |  Branch (75:51): [True: 0, False: 0]
  |  Branch (75:69): [True: 0, False: 0]
  ------------------
   76|      0|            if (id_idx == ZIP_EXTRA_FIELD_ALL || i == id_idx) {
  ------------------
  |  |  121|      0|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (76:17): [True: 0, False: 0]
  |  Branch (76:50): [True: 0, False: 0]
  ------------------
   77|      0|                ef->flags &= ~(flags & ZIP_EF_BOTH);
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   78|      0|                if ((ef->flags & ZIP_EF_BOTH) == 0) {
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (78:21): [True: 0, False: 0]
  ------------------
   79|      0|                    if (prev) {
  ------------------
  |  Branch (79:25): [True: 0, False: 0]
  ------------------
   80|      0|                        prev->next = ef->next;
   81|      0|                    }
   82|      0|                    else {
   83|      0|                        head = ef->next;
   84|      0|                    }
   85|      0|                    ef->next = NULL;
   86|      0|                    _zip_ef_free(ef);
   87|       |
   88|      0|                    if (id_idx == ZIP_EXTRA_FIELD_ALL) {
  ------------------
  |  |  121|      0|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (88:25): [True: 0, False: 0]
  ------------------
   89|      0|                        continue;
   90|      0|                    }
   91|      0|                }
   92|      0|            }
   93|       |
   94|      0|            i++;
   95|      0|            if (i > id_idx) {
  ------------------
  |  Branch (95:17): [True: 0, False: 0]
  ------------------
   96|      0|                break;
   97|      0|            }
   98|      0|        }
   99|      0|        prev = ef;
  100|      0|    }
  101|       |
  102|    490|    return head;
  103|    490|}
_zip_ef_free:
  106|  1.96k|void _zip_ef_free(zip_extra_field_t *ef) {
  107|  1.96k|    zip_extra_field_t *ef2;
  108|       |
  109|  1.96k|    while (ef) {
  ------------------
  |  Branch (109:12): [True: 0, False: 1.96k]
  ------------------
  110|      0|        ef2 = ef->next;
  111|      0|        free(ef->data);
  112|      0|        free(ef);
  113|      0|        ef = ef2;
  114|      0|    }
  115|  1.96k|}
_zip_ef_size:
  309|  2.94k|zip_uint32_t _zip_ef_size(const zip_extra_field_t *ef, zip_flags_t flags) {
  310|  2.94k|    zip_uint32_t size;
  311|       |
  312|  2.94k|    size = 0;
  313|  2.94k|    for (; ef; ef = ef->next) {
  ------------------
  |  Branch (313:12): [True: 0, False: 2.94k]
  ------------------
  314|      0|        if (ef->flags & flags & ZIP_EF_BOTH) {
  ------------------
  |  |  260|      0|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|      0|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (314:13): [True: 0, False: 0]
  ------------------
  315|      0|            size = (zip_uint32_t)(size + 4 + ef->size);
  316|      0|        }
  317|      0|    }
  318|       |
  319|  2.94k|    return size;
  320|  2.94k|}
_zip_read_local_ef:
  359|    490|int _zip_read_local_ef(zip_t *za, zip_uint64_t idx) {
  360|    490|    zip_entry_t *e;
  361|    490|    unsigned char b[4];
  362|    490|    zip_buffer_t *buffer;
  363|    490|    zip_uint16_t fname_len, ef_len;
  364|       |
  365|    490|    if (idx >= za->nentry) {
  ------------------
  |  Branch (365:9): [True: 0, False: 490]
  ------------------
  366|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  367|      0|        return -1;
  368|      0|    }
  369|       |
  370|    490|    e = za->entry + idx;
  371|       |
  372|    490|    if (e->orig == NULL || e->orig->local_extra_fields_read) {
  ------------------
  |  Branch (372:9): [True: 490, False: 0]
  |  Branch (372:28): [True: 0, False: 0]
  ------------------
  373|    490|        return 0;
  374|    490|    }
  375|       |
  376|      0|    if (e->orig->offset + 26 > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (376:9): [True: 0, False: 0]
  ------------------
  377|      0|        zip_error_set(&za->error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  378|      0|        return -1;
  379|      0|    }
  380|       |
  381|      0|    if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) {
  ------------------
  |  Branch (381:9): [True: 0, False: 0]
  ------------------
  382|      0|        zip_error_set_from_source(&za->error, za->src);
  383|      0|        return -1;
  384|      0|    }
  385|       |
  386|      0|    if ((buffer = _zip_buffer_new_from_source(za->src, sizeof(b), b, &za->error)) == NULL) {
  ------------------
  |  Branch (386:9): [True: 0, False: 0]
  ------------------
  387|      0|        return -1;
  388|      0|    }
  389|       |
  390|      0|    fname_len = _zip_buffer_get_16(buffer);
  391|      0|    ef_len = _zip_buffer_get_16(buffer);
  392|       |
  393|      0|    if (!_zip_buffer_eof(buffer)) {
  ------------------
  |  Branch (393:9): [True: 0, False: 0]
  ------------------
  394|      0|        _zip_buffer_free(buffer);
  395|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  396|      0|        return -1;
  397|      0|    }
  398|       |
  399|      0|    _zip_buffer_free(buffer);
  400|       |
  401|      0|    if (ef_len > 0) {
  ------------------
  |  Branch (401:9): [True: 0, False: 0]
  ------------------
  402|      0|        zip_extra_field_t *ef;
  403|      0|        zip_uint8_t *ef_raw;
  404|       |
  405|      0|        if (zip_source_seek(za->src, fname_len, SEEK_CUR) < 0) {
  ------------------
  |  Branch (405:13): [True: 0, False: 0]
  ------------------
  406|      0|            zip_error_set(&za->error, ZIP_ER_SEEK, errno);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  407|      0|            return -1;
  408|      0|        }
  409|       |
  410|      0|        ef_raw = _zip_read_data(NULL, za->src, ef_len, 0, &za->error);
  411|       |
  412|      0|        if (ef_raw == NULL) {
  ------------------
  |  Branch (412:13): [True: 0, False: 0]
  ------------------
  413|      0|            return -1;
  414|      0|        }
  415|       |
  416|      0|        if (!_zip_ef_parse(ef_raw, ef_len, ZIP_EF_LOCAL, &ef, &za->error)) {
  ------------------
  |  |  258|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (416:13): [True: 0, False: 0]
  ------------------
  417|      0|            free(ef_raw);
  418|      0|            return -1;
  419|      0|        }
  420|      0|        free(ef_raw);
  421|       |
  422|      0|        if (ef) {
  ------------------
  |  Branch (422:13): [True: 0, False: 0]
  ------------------
  423|      0|            ef = _zip_ef_remove_internal(ef);
  424|      0|            e->orig->extra_fields = _zip_ef_merge(e->orig->extra_fields, ef);
  425|      0|        }
  426|      0|    }
  427|       |
  428|      0|    e->orig->local_extra_fields_read = 1;
  429|       |
  430|      0|    if (e->changes && e->changes->local_extra_fields_read == 0) {
  ------------------
  |  Branch (430:9): [True: 0, False: 0]
  |  Branch (430:23): [True: 0, False: 0]
  ------------------
  431|      0|        e->changes->extra_fields = e->orig->extra_fields;
  432|      0|        e->changes->local_extra_fields_read = 1;
  433|      0|    }
  434|       |
  435|      0|    return 0;
  436|      0|}

zip_file_extra_field_delete:
   38|    490|ZIP_EXTERN int zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags) {
   39|    490|    zip_dirent_t *de;
   40|       |
   41|    490|    if ((flags & ZIP_EF_BOTH) == 0) {
  ------------------
  |  |  260|    490|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|    490|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|    490|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|    490|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|    490|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (41:9): [True: 0, False: 490]
  ------------------
   42|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|    490|    if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  260|    490|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|    490|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|    490|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|    490|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|    490|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  260|    490|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  258|    490|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|    490|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  259|    490|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|    490|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  121|    490|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    490|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (46:9): [True: 490, False: 0]
  |  Branch (46:51): [True: 0, False: 490]
  ------------------
   47|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|    490|    if (_zip_get_dirent(za, idx, 0, NULL) == NULL) {
  ------------------
  |  Branch (51:9): [True: 0, False: 490]
  ------------------
   52|      0|        return -1;
   53|      0|    }
   54|       |
   55|    490|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  509|    490|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|    490|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (509:27): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   56|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   57|      0|        return -1;
   58|      0|    }
   59|       |
   60|    490|    if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) {
  ------------------
  |  Branch (60:9): [True: 0, False: 490]
  ------------------
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|    490|    de = za->entry[idx].changes;
   65|       |
   66|    490|    de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ZIP_EXTRA_FIELD_ALL, ef_idx, flags);
  ------------------
  |  |  121|    490|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    490|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
   67|    490|    return 0;
   68|    490|}
_zip_file_extra_field_prepare_for_change:
  357|    490|int _zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx) {
  358|    490|    zip_entry_t *e;
  359|       |
  360|    490|    if (idx >= za->nentry) {
  ------------------
  |  Branch (360:9): [True: 0, False: 490]
  ------------------
  361|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  362|      0|        return -1;
  363|      0|    }
  364|       |
  365|    490|    e = za->entry + idx;
  366|       |
  367|    490|    if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD)) {
  ------------------
  |  |  336|    490|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  |  Branch (367:9): [True: 490, False: 0]
  |  Branch (367:23): [True: 0, False: 490]
  ------------------
  368|      0|        return 0;
  369|      0|    }
  370|       |
  371|    490|    if (e->orig) {
  ------------------
  |  Branch (371:9): [True: 0, False: 490]
  ------------------
  372|      0|        if (_zip_read_local_ef(za, idx) < 0) {
  ------------------
  |  Branch (372:13): [True: 0, False: 0]
  ------------------
  373|      0|            return -1;
  374|      0|        }
  375|      0|    }
  376|       |
  377|    490|    if (e->changes == NULL) {
  ------------------
  |  Branch (377:9): [True: 0, False: 490]
  ------------------
  378|      0|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (378:13): [True: 0, False: 0]
  ------------------
  379|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  380|      0|            return -1;
  381|      0|        }
  382|      0|    }
  383|       |
  384|    490|    if (e->orig && e->orig->extra_fields) {
  ------------------
  |  Branch (384:9): [True: 0, False: 490]
  |  Branch (384:20): [True: 0, False: 0]
  ------------------
  385|      0|        if ((e->changes->extra_fields = _zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL) {
  ------------------
  |  Branch (385:13): [True: 0, False: 0]
  ------------------
  386|      0|            return -1;
  387|      0|        }
  388|      0|    }
  389|    490|    e->changes->changed |= ZIP_DIRENT_EXTRA_FIELD;
  ------------------
  |  |  336|    490|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  390|       |
  391|    490|    return 0;
  392|    490|}

zip_file_add:
   44|    490|ZIP_EXTERN zip_int64_t zip_file_add(zip_t *za, const char *name, zip_source_t *source, zip_flags_t flags) {
   45|    490|    if (name == NULL || source == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 490]
  |  Branch (45:25): [True: 0, False: 490]
  ------------------
   46|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|    490|    return _zip_file_replace(za, ZIP_UINT64_MAX, name, source, flags);
  ------------------
  |  |   46|    490|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   51|    490|}

_zip_file_replace:
   54|    490|zip_int64_t _zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *source, zip_flags_t flags) {
   55|    490|    zip_uint64_t za_nentry_prev;
   56|       |
   57|    490|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  509|    490|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|    490|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (509:27): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   58|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   59|      0|        return -1;
   60|      0|    }
   61|       |
   62|    490|    za_nentry_prev = za->nentry;
   63|    490|    if (idx == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|    490|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (63:9): [True: 490, False: 0]
  ------------------
   64|    490|        zip_int64_t i = -1;
   65|       |
   66|    490|        if (flags & ZIP_FL_OVERWRITE) {
  ------------------
  |  |  109|    490|#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
  ------------------
  |  Branch (66:13): [True: 490, False: 0]
  ------------------
   67|    490|            i = _zip_name_locate(za, name, flags, NULL);
   68|    490|        }
   69|       |
   70|    490|        if (i == -1) {
  ------------------
  |  Branch (70:13): [True: 490, False: 0]
  ------------------
   71|       |            /* create and use new entry, used by zip_add */
   72|    490|            if ((i = _zip_add_entry(za)) < 0) {
  ------------------
  |  Branch (72:17): [True: 0, False: 490]
  ------------------
   73|      0|                return -1;
   74|      0|            }
   75|    490|        }
   76|    490|        idx = (zip_uint64_t)i;
   77|    490|    }
   78|       |
   79|    490|    if (name && _zip_set_name(za, idx, name, flags) != 0) {
  ------------------
  |  Branch (79:9): [True: 490, False: 0]
  |  Branch (79:17): [True: 0, False: 490]
  ------------------
   80|      0|        if (za->nentry != za_nentry_prev) {
  ------------------
  |  Branch (80:13): [True: 0, False: 0]
  ------------------
   81|      0|            _zip_entry_finalize(za->entry + idx);
   82|      0|            za->nentry = za_nentry_prev;
   83|      0|        }
   84|      0|        return -1;
   85|      0|    }
   86|       |
   87|       |    /* delete all extra fields - these are usually data that are
   88|       |     * strongly coupled with the original data */
   89|    490|    if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  121|    490|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    490|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
                  if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  105|    490|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
                  if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  104|    490|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (89:9): [True: 0, False: 490]
  ------------------
   90|      0|        return -1;
   91|      0|    }
   92|       |
   93|       |    /* does not change any name related data, so we can do it here;
   94|       |     * needed for a double add of the same file name */
   95|    490|    _zip_unchange_data(za->entry + idx);
   96|       |
   97|    490|    za->entry[idx].source = source;
   98|       |
   99|    490|    return (zip_int64_t)idx;
  100|    490|}

zip_file_set_encryption:
   40|    490|ZIP_EXTERN int zip_file_set_encryption(zip_t *za, zip_uint64_t idx, zip_uint16_t method, const char *password) {
   41|    490|    zip_entry_t *e;
   42|    490|    char *our_password = NULL;
   43|       |
   44|    490|    if (idx >= za->nentry) {
  ------------------
  |  Branch (44:9): [True: 0, False: 490]
  ------------------
   45|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|    490|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  509|    490|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|    490|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (509:27): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   50|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|    490|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  511|    490|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|    490|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (511:33): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   54|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
   55|      0|        return -1;
   56|      0|    }
   57|       |
   58|    490|    if (method != ZIP_EM_NONE && _zip_get_encryption_implementation(method, ZIP_CODEC_ENCODE) == NULL) {
  ------------------
  |  |  207|    980|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
                  if (method != ZIP_EM_NONE && _zip_get_encryption_implementation(method, ZIP_CODEC_ENCODE) == NULL) {
  ------------------
  |  |  115|    490|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (58:9): [True: 490, False: 0]
  |  Branch (58:34): [True: 0, False: 490]
  ------------------
   59|      0|        zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|    490|    e = za->entry + idx;
   64|       |
   65|       |
   66|    490|    if (e->changes == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 490]
  ------------------
   67|      0|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (67:13): [True: 0, False: 0]
  ------------------
   68|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   69|      0|            return -1;
   70|      0|        }
   71|      0|    }
   72|       |
   73|    490|    if (password) {
  ------------------
  |  Branch (73:9): [True: 490, False: 0]
  ------------------
   74|    490|        if ((our_password = strdup(password)) == NULL) {
  ------------------
  |  Branch (74:13): [True: 0, False: 490]
  ------------------
   75|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   76|      0|            return -1;
   77|      0|        }
   78|    490|    }
   79|       |
   80|    490|    e->changes->encryption_method = method;
   81|    490|    e->changes->changed |= ZIP_DIRENT_ENCRYPTION_METHOD;
  ------------------
  |  |  339|    490|#define ZIP_DIRENT_ENCRYPTION_METHOD 0x0040u
  ------------------
   82|    490|    if (e->changes->changed & ZIP_DIRENT_PASSWORD) {
  ------------------
  |  |  340|    490|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (82:9): [True: 0, False: 490]
  ------------------
   83|      0|        _zip_crypto_clear(e->changes->password, strlen(e->changes->password));
  ------------------
  |  |  521|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
   84|      0|        free(e->changes->password);
   85|      0|    }
   86|    490|    if (password) {
  ------------------
  |  Branch (86:9): [True: 490, False: 0]
  ------------------
   87|    490|        e->changes->password = our_password;
   88|    490|        e->changes->changed |= ZIP_DIRENT_PASSWORD;
  ------------------
  |  |  340|    490|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
   89|    490|    }
   90|      0|    else {
   91|      0|        e->changes->password = e->orig ? e->orig->password : NULL;
  ------------------
  |  Branch (91:32): [True: 0, False: 0]
  ------------------
   92|      0|        e->changes->changed &= ~ZIP_DIRENT_PASSWORD;
  ------------------
  |  |  340|      0|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
   93|      0|    }
   94|       |
   95|    490|    return 0;
   96|    490|}

_zip_get_encryption_implementation:
   38|    980|zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t em, int operation) {
   39|    980|    switch (em) {
   40|    980|    case ZIP_EM_TRAD_PKWARE:
  ------------------
  |  |  208|    980|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (40:5): [True: 980, False: 0]
  ------------------
   41|    980|        return operation == ZIP_CODEC_DECODE ? zip_source_pkware_decode : zip_source_pkware_encode;
  ------------------
  |  |  114|    980|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (41:16): [True: 0, False: 980]
  ------------------
   42|       |
   43|      0|#if defined(HAVE_CRYPTO)
   44|      0|    case ZIP_EM_AES_128:
  ------------------
  |  |  220|      0|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
  |  Branch (44:5): [True: 0, False: 980]
  ------------------
   45|      0|    case ZIP_EM_AES_192:
  ------------------
  |  |  221|      0|#define ZIP_EM_AES_192 0x0102
  ------------------
  |  Branch (45:5): [True: 0, False: 980]
  ------------------
   46|      0|    case ZIP_EM_AES_256:
  ------------------
  |  |  222|      0|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (46:5): [True: 0, False: 980]
  ------------------
   47|      0|        return operation == ZIP_CODEC_DECODE ? zip_source_winzip_aes_decode : zip_source_winzip_aes_encode;
  ------------------
  |  |  114|      0|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (47:16): [True: 0, False: 0]
  ------------------
   48|      0|#endif
   49|       |
   50|      0|    default:
  ------------------
  |  Branch (50:5): [True: 0, False: 980]
  ------------------
   51|       |        return NULL;
   52|    980|    }
   53|    980|}

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

_zip_hash_new:
  162|    490|zip_hash_t *_zip_hash_new(zip_error_t *error) {
  163|    490|    zip_hash_t *hash;
  164|       |
  165|    490|    if ((hash = (zip_hash_t *)malloc(sizeof(zip_hash_t))) == NULL) {
  ------------------
  |  Branch (165:9): [True: 0, False: 490]
  ------------------
  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|    490|    hash->table_size = 0;
  171|    490|    hash->nentries = 0;
  172|    490|    hash->table = NULL;
  173|       |
  174|    490|    return hash;
  175|    490|}
_zip_hash_free:
  178|    490|void _zip_hash_free(zip_hash_t *hash) {
  179|    490|    zip_uint32_t i;
  180|       |
  181|    490|    if (hash == NULL) {
  ------------------
  |  Branch (181:9): [True: 0, False: 490]
  ------------------
  182|      0|        return;
  183|      0|    }
  184|       |
  185|    490|    if (hash->table != NULL) {
  ------------------
  |  Branch (185:9): [True: 490, False: 0]
  ------------------
  186|   125k|        for (i = 0; i < hash->table_size; i++) {
  ------------------
  |  Branch (186:21): [True: 125k, False: 490]
  ------------------
  187|   125k|            if (hash->table[i] != NULL) {
  ------------------
  |  Branch (187:17): [True: 490, False: 124k]
  ------------------
  188|    490|                free_list(hash->table[i]);
  189|    490|            }
  190|   125k|        }
  191|    490|        free(hash->table);
  192|    490|    }
  193|    490|    free(hash);
  194|    490|}
_zip_hash_add:
  198|    490|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|    490|    zip_uint32_t hash_value, table_index;
  200|    490|    zip_hash_entry_t *entry;
  201|       |
  202|    490|    if (hash == NULL || name == NULL || index > ZIP_INT64_MAX) {
  ------------------
  |  |   45|    490|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (202:9): [True: 0, False: 490]
  |  Branch (202:25): [True: 0, False: 490]
  |  Branch (202:41): [True: 0, False: 490]
  ------------------
  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|    490|    if (hash->table_size == 0) {
  ------------------
  |  Branch (207:9): [True: 490, False: 0]
  ------------------
  208|    490|        if (!hash_resize(hash, HASH_MIN_SIZE, error)) {
  ------------------
  |  |   47|    490|#define HASH_MIN_SIZE 256
  ------------------
  |  Branch (208:13): [True: 0, False: 490]
  ------------------
  209|      0|            return false;
  210|      0|        }
  211|    490|    }
  212|       |
  213|    490|    hash_value = hash_string(name);
  214|    490|    table_index = hash_value % hash->table_size;
  215|       |
  216|    490|    for (entry = hash->table[table_index]; entry != NULL; entry = entry->next) {
  ------------------
  |  Branch (216:44): [True: 0, False: 490]
  ------------------
  217|      0|        if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
  ------------------
  |  Branch (217:13): [True: 0, False: 0]
  |  Branch (217:48): [True: 0, False: 0]
  ------------------
  218|      0|            if (((flags & ZIP_FL_UNCHANGED) && entry->orig_index != -1) || entry->current_index != -1) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (218:18): [True: 0, False: 0]
  |  Branch (218:48): [True: 0, False: 0]
  |  Branch (218:76): [True: 0, False: 0]
  ------------------
  219|      0|                zip_error_set(error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
  220|      0|                return false;
  221|      0|            }
  222|      0|            else {
  223|      0|                break;
  224|      0|            }
  225|      0|        }
  226|      0|    }
  227|       |
  228|    490|    if (entry == NULL) {
  ------------------
  |  Branch (228:9): [True: 490, False: 0]
  ------------------
  229|    490|        if ((entry = (zip_hash_entry_t *)malloc(sizeof(zip_hash_entry_t))) == NULL) {
  ------------------
  |  Branch (229:13): [True: 0, False: 490]
  ------------------
  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|    490|        entry->name = name;
  234|    490|        entry->next = hash->table[table_index];
  235|    490|        hash->table[table_index] = entry;
  236|    490|        entry->hash_value = hash_value;
  237|    490|        entry->orig_index = -1;
  238|    490|        hash->nentries++;
  239|    490|        if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
  ------------------
  |  |   43|    980|#define HASH_MAX_FILL .75
  ------------------
                      if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
  ------------------
  |  |   48|      0|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  |  Branch (239:13): [True: 0, False: 490]
  |  Branch (239:66): [True: 0, False: 0]
  ------------------
  240|      0|            if (!hash_resize(hash, hash->table_size * 2, error)) {
  ------------------
  |  Branch (240:17): [True: 0, False: 0]
  ------------------
  241|      0|                return false;
  242|      0|            }
  243|      0|        }
  244|    490|    }
  245|       |
  246|    490|    if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|    490|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (246:9): [True: 0, False: 490]
  ------------------
  247|      0|        entry->orig_index = (zip_int64_t)index;
  248|      0|    }
  249|    490|    entry->current_index = (zip_int64_t)index;
  250|       |
  251|       |    return true;
  252|    490|}
_zip_hash_lookup:
  303|    980|zip_int64_t _zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error) {
  304|    980|    zip_uint32_t hash_value, index;
  305|    980|    zip_hash_entry_t *entry;
  306|       |
  307|    980|    if (hash == NULL || name == NULL) {
  ------------------
  |  Branch (307:9): [True: 0, False: 980]
  |  Branch (307:25): [True: 0, False: 980]
  ------------------
  308|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|    980|    if (hash->nentries > 0) {
  ------------------
  |  Branch (312:9): [True: 0, False: 980]
  ------------------
  313|      0|        hash_value = hash_string(name);
  314|      0|        index = hash_value % hash->table_size;
  315|      0|        for (entry = hash->table[index]; entry != NULL; entry = entry->next) {
  ------------------
  |  Branch (315:42): [True: 0, False: 0]
  ------------------
  316|      0|            if (strcmp((const char *)name, (const char *)entry->name) == 0) {
  ------------------
  |  Branch (316:17): [True: 0, False: 0]
  ------------------
  317|      0|                if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (317:21): [True: 0, False: 0]
  ------------------
  318|      0|                    if (entry->orig_index != -1) {
  ------------------
  |  Branch (318:25): [True: 0, False: 0]
  ------------------
  319|      0|                        return entry->orig_index;
  320|      0|                    }
  321|      0|                }
  322|      0|                else {
  323|      0|                    if (entry->current_index != -1) {
  ------------------
  |  Branch (323:25): [True: 0, False: 0]
  ------------------
  324|      0|                        return entry->current_index;
  325|      0|                    }
  326|      0|                }
  327|      0|                break;
  328|      0|            }
  329|      0|        }
  330|      0|    }
  331|       |
  332|    980|    zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|    980|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  333|    980|    return -1;
  334|    980|}
zip_hash.c:free_list:
   67|    490|static void free_list(zip_hash_entry_t *entry) {
   68|    980|    while (entry != NULL) {
  ------------------
  |  Branch (68:12): [True: 490, False: 490]
  ------------------
   69|    490|        zip_hash_entry_t *next = entry->next;
   70|    490|        free(entry);
   71|    490|        entry = next;
   72|    490|    }
   73|    490|}
zip_hash.c:hash_resize:
   94|    490|static bool hash_resize(zip_hash_t *hash, zip_uint32_t new_size, zip_error_t *error) {
   95|    490|    zip_hash_entry_t **new_table;
   96|       |
   97|    490|    if (new_size == hash->table_size) {
  ------------------
  |  Branch (97:9): [True: 0, False: 490]
  ------------------
   98|      0|        return true;
   99|      0|    }
  100|       |
  101|    490|    if ((new_table = (zip_hash_entry_t **)calloc(new_size, sizeof(zip_hash_entry_t *))) == NULL) {
  ------------------
  |  Branch (101:9): [True: 0, False: 490]
  ------------------
  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|    490|    if (hash->nentries > 0) {
  ------------------
  |  Branch (106:9): [True: 0, False: 490]
  ------------------
  107|      0|        zip_uint32_t i;
  108|       |
  109|      0|        for (i = 0; i < hash->table_size; i++) {
  ------------------
  |  Branch (109:21): [True: 0, False: 0]
  ------------------
  110|      0|            zip_hash_entry_t *entry = hash->table[i];
  111|      0|            while (entry) {
  ------------------
  |  Branch (111:20): [True: 0, False: 0]
  ------------------
  112|      0|                zip_hash_entry_t *next = entry->next;
  113|       |
  114|      0|                zip_uint32_t new_index = entry->hash_value % new_size;
  115|       |
  116|      0|                entry->next = new_table[new_index];
  117|      0|                new_table[new_index] = entry;
  118|       |
  119|      0|                entry = next;
  120|      0|            }
  121|      0|        }
  122|      0|    }
  123|       |
  124|    490|    free(hash->table);
  125|    490|    hash->table = new_table;
  126|    490|    hash->table_size = new_size;
  127|       |
  128|       |    return true;
  129|    490|}
zip_hash.c:hash_string:
   77|    490|static zip_uint32_t hash_string(const zip_uint8_t *name) {
   78|    490|    zip_uint64_t value = HASH_START;
  ------------------
  |  |   40|    490|#define HASH_START 5381
  ------------------
   79|       |
   80|    490|    if (name == NULL) {
  ------------------
  |  Branch (80:9): [True: 0, False: 490]
  ------------------
   81|      0|        return 0;
   82|      0|    }
   83|       |
   84|  4.41k|    while (*name != 0) {
  ------------------
  |  Branch (84:12): [True: 3.92k, False: 490]
  ------------------
   85|  3.92k|        value = (zip_uint64_t)(((value * HASH_MULTIPLIER) + (zip_uint8_t)*name) % 0x100000000ul);
  ------------------
  |  |   39|  3.92k|#define HASH_MULTIPLIER 33
  ------------------
   86|  3.92k|        name++;
   87|  3.92k|    }
   88|       |
   89|    490|    return (zip_uint32_t)value;
   90|    490|}

_zip_write:
  115|  14.6k|int _zip_write(zip_t *za, const void *data, zip_uint64_t length) {
  116|  14.6k|    zip_int64_t n;
  117|       |
  118|  14.6k|    if ((n = zip_source_write(za->src, data, length)) < 0) {
  ------------------
  |  Branch (118:9): [True: 0, False: 14.6k]
  ------------------
  119|      0|        zip_error_set_from_source(&za->error, za->src);
  120|      0|        return -1;
  121|      0|    }
  122|  14.6k|    if ((zip_uint64_t)n != length) {
  ------------------
  |  Branch (122:9): [True: 0, False: 14.6k]
  ------------------
  123|      0|        zip_error_set(&za->error, ZIP_ER_WRITE, EINTR);
  ------------------
  |  |  137|      0|#define ZIP_ER_WRITE 6            /* S Write error */
  ------------------
  124|      0|        return -1;
  125|      0|    }
  126|       |
  127|  14.6k|    if (za->write_crc != NULL) {
  ------------------
  |  Branch (127:9): [True: 0, False: 14.6k]
  ------------------
  128|      0|        zip_uint64_t position = 0;
  129|      0|        while (position < length) {
  ------------------
  |  Branch (129:16): [True: 0, False: 0]
  ------------------
  130|      0|            zip_uint64_t nn = ZIP_MIN(UINT_MAX, length - position);
  ------------------
  |  |  503|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  131|       |
  132|      0|            *za->write_crc = (zip_uint32_t)crc32(*za->write_crc, (const Bytef *)data + position, (uInt)nn);
  133|      0|            position += nn;
  134|      0|        }
  135|      0|    }
  136|       |
  137|  14.6k|    return 0;
  138|  14.6k|}

_zip_name_locate:
   48|    980|zip_int64_t _zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error) {
   49|    980|    int (*cmp)(const char *, const char *);
   50|    980|    size_t fname_length;
   51|    980|    zip_string_t *str = NULL;
   52|    980|    const char *fn, *p;
   53|    980|    zip_uint64_t i;
   54|       |
   55|    980|    if (za == NULL) {
  ------------------
  |  Branch (55:9): [True: 0, False: 980]
  ------------------
   56|      0|        return -1;
   57|      0|    }
   58|       |
   59|    980|    if (fname == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 980]
  ------------------
   60|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|    980|    fname_length = strlen(fname);
   65|       |
   66|    980|    if (fname_length > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|    980|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (66:9): [True: 0, False: 980]
  ------------------
   67|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   68|      0|        return -1;
   69|      0|    }
   70|       |
   71|    980|    if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
  ------------------
  |  |  107|    980|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
                  if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
  ------------------
  |  |  102|    980|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
  |  Branch (71:9): [True: 980, False: 0]
  |  Branch (71:63): [True: 980, False: 0]
  ------------------
   72|    980|        if ((str = _zip_string_new((const zip_uint8_t *)fname, (zip_uint16_t)strlen(fname), flags, error)) == NULL) {
  ------------------
  |  Branch (72:13): [True: 0, False: 980]
  ------------------
   73|      0|            return -1;
   74|      0|        }
   75|    980|        if ((fname = (const char *)_zip_string_get(str, NULL, 0, error)) == NULL) {
  ------------------
  |  Branch (75:13): [True: 0, False: 980]
  ------------------
   76|      0|            _zip_string_free(str);
   77|      0|            return -1;
   78|      0|        }
   79|    980|    }
   80|       |
   81|    980|    if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |   95|    980|#define ZIP_FL_NOCASE 1u     /* ignore case on name lookup */
  ------------------
                  if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |   96|    980|#define ZIP_FL_NODIR 2u      /* ignore directory component */
  ------------------
                  if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |  102|    980|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
                  if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |  103|    980|#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
  ------------------
  |  Branch (81:9): [True: 0, False: 980]
  ------------------
   82|       |        /* can't use hash table */
   83|      0|        cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
  ------------------
  |  |   95|      0|#define ZIP_FL_NOCASE 1u     /* ignore case on name lookup */
  ------------------
  |  Branch (83:15): [True: 0, False: 0]
  ------------------
   84|       |
   85|      0|        for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (85:21): [True: 0, False: 0]
  ------------------
   86|      0|            fn = _zip_get_name(za, i, flags, error);
   87|       |
   88|       |            /* newly added (partially filled) entry or error */
   89|      0|            if (fn == NULL) {
  ------------------
  |  Branch (89:17): [True: 0, False: 0]
  ------------------
   90|      0|                continue;
   91|      0|            }
   92|       |
   93|      0|            if (flags & ZIP_FL_NODIR) {
  ------------------
  |  |   96|      0|#define ZIP_FL_NODIR 2u      /* ignore directory component */
  ------------------
  |  Branch (93:17): [True: 0, False: 0]
  ------------------
   94|      0|                p = strrchr(fn, '/');
   95|      0|                if (p) {
  ------------------
  |  Branch (95:21): [True: 0, False: 0]
  ------------------
   96|      0|                    fn = p + 1;
   97|      0|                }
   98|      0|            }
   99|       |
  100|      0|            if (cmp(fname, fn) == 0) {
  ------------------
  |  Branch (100:17): [True: 0, False: 0]
  ------------------
  101|      0|                _zip_error_clear(error);
  102|      0|                _zip_string_free(str);
  103|      0|                return (zip_int64_t)i;
  104|      0|            }
  105|      0|        }
  106|       |
  107|      0|        zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|      0|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  108|      0|        _zip_string_free(str);
  109|      0|        return -1;
  110|      0|    }
  111|    980|    else {
  112|    980|        zip_int64_t ret = _zip_hash_lookup(za->names, (const zip_uint8_t *)fname, flags, error);
  113|    980|        _zip_string_free(str);
  114|    980|        return ret;
  115|    980|    }
  116|    980|}

_zip_new:
   44|    490|zip_t *_zip_new(zip_error_t *error) {
   45|    490|    zip_t *za;
   46|       |
   47|    490|    za = (zip_t *)malloc(sizeof(struct zip));
   48|    490|    if (za == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 490]
  ------------------
   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|    490|    if ((za->names = _zip_hash_new(error)) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 490]
  ------------------
   54|      0|        free(za);
   55|      0|        return NULL;
   56|      0|    }
   57|       |
   58|    490|    za->src = NULL;
   59|    490|    za->open_flags = 0;
   60|    490|    zip_error_init(&za->error);
   61|    490|    za->flags = za->ch_flags = 0;
   62|    490|    za->default_password = NULL;
   63|    490|    za->comment_orig = za->comment_changes = NULL;
   64|    490|    za->comment_changed = 0;
   65|    490|    za->nentry = za->nentry_alloc = 0;
   66|    490|    za->entry = NULL;
   67|    490|    za->nopen_source = za->nopen_source_alloc = 0;
   68|    490|    za->open_source = NULL;
   69|    490|    za->progress = NULL;
   70|    490|    za->torrent_mtime = 0;
   71|       |
   72|    490|    return za;
   73|    490|}

zip_open:
   67|    490|ZIP_EXTERN zip_t *zip_open(const char *fn, int _flags, int *zep) {
   68|    490|    zip_t *za;
   69|    490|    zip_source_t *src;
   70|    490|    struct zip_error error;
   71|       |
   72|    490|    zip_error_init(&error);
   73|    490|    if ((src = zip_source_file_create(fn, 0, -1, &error)) == NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 490]
  ------------------
   74|      0|        _zip_set_open_error(zep, &error, 0);
   75|      0|        zip_error_fini(&error);
   76|      0|        return NULL;
   77|      0|    }
   78|       |
   79|    490|    if ((za = zip_open_from_source(src, _flags, &error)) == NULL) {
  ------------------
  |  Branch (79:9): [True: 0, False: 490]
  ------------------
   80|      0|        zip_source_free(src);
   81|      0|        _zip_set_open_error(zep, &error, 0);
   82|      0|        zip_error_fini(&error);
   83|      0|        return NULL;
   84|      0|    }
   85|       |
   86|    490|    zip_error_fini(&error);
   87|    490|    return za;
   88|    490|}
zip_open_from_source:
   91|    490|ZIP_EXTERN zip_t *zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
   92|    490|    unsigned int flags;
   93|    490|    zip_int64_t supported;
   94|    490|    exists_t exists;
   95|       |
   96|    490|    if (_flags < 0 || src == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 490]
  |  Branch (96:23): [True: 0, False: 490]
  ------------------
   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|    490|    flags = (unsigned int)_flags;
  101|       |
  102|    490|    supported = zip_source_supports(src);
  103|    490|    if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
  ------------------
  |  |  288|    490|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  289|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  290|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
  ------------------
  |  |  288|    490|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  289|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  290|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  |  Branch (103:9): [True: 0, False: 490]
  ------------------
  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|    490|    if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
  ------------------
  |  |  293|    490|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  288|    490|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  289|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  290|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  294|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  295|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
  ------------------
  |  |  293|    490|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  288|    490|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  289|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  290|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  294|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  295|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  |  Branch (107:9): [True: 0, False: 490]
  ------------------
  108|      0|        flags |= ZIP_RDONLY;
  ------------------
  |  |   90|      0|#define ZIP_RDONLY 16
  ------------------
  109|      0|    }
  110|       |
  111|    490|    if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   90|    490|#define ZIP_RDONLY 16
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   89|    490|#define ZIP_TRUNCATE 8
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   90|    490|#define ZIP_RDONLY 16
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   89|    490|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (111:9): [True: 0, False: 490]
  ------------------
  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|    490|    exists = _zip_file_exists(src, error);
  117|    490|    switch (exists) {
  118|      0|    case EXISTS_ERROR:
  ------------------
  |  Branch (118:5): [True: 0, False: 490]
  ------------------
  119|      0|        return NULL;
  120|       |
  121|    490|    case EXISTS_NOT:
  ------------------
  |  Branch (121:5): [True: 490, False: 0]
  ------------------
  122|    490|        if ((flags & ZIP_CREATE) == 0) {
  ------------------
  |  |   86|    490|#define ZIP_CREATE 1
  ------------------
  |  Branch (122:13): [True: 0, False: 490]
  ------------------
  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|    490|        return _zip_allocate_new(src, flags, error);
  127|       |
  128|      0|    default: {
  ------------------
  |  Branch (128:5): [True: 0, False: 490]
  ------------------
  129|      0|        zip_t *za;
  130|      0|        if (flags & ZIP_EXCL) {
  ------------------
  |  |   87|      0|#define ZIP_EXCL 2
  ------------------
  |  Branch (130:13): [True: 0, False: 0]
  ------------------
  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|      0|        if (zip_source_open(src) < 0) {
  ------------------
  |  Branch (134:13): [True: 0, False: 0]
  ------------------
  135|      0|            zip_error_set_from_source(error, src);
  136|      0|            return NULL;
  137|      0|        }
  138|       |
  139|      0|        if (flags & ZIP_TRUNCATE) {
  ------------------
  |  |   89|      0|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (139:13): [True: 0, False: 0]
  ------------------
  140|      0|            za = _zip_allocate_new(src, flags, error);
  141|      0|        }
  142|      0|        else {
  143|       |            /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL, just like open() */
  144|      0|            za = _zip_open(src, flags, error);
  145|      0|        }
  146|       |
  147|      0|        if (za == NULL) {
  ------------------
  |  Branch (147:13): [True: 0, False: 0]
  ------------------
  148|      0|            zip_source_close(src);
  149|      0|            return NULL;
  150|      0|        }
  151|      0|        return za;
  152|      0|    }
  153|    490|    }
  154|    490|}
zip_open.c:_zip_allocate_new:
  626|    490|static zip_t *_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error) {
  627|    490|    zip_t *za;
  628|       |
  629|    490|    if ((za = _zip_new(error)) == NULL) {
  ------------------
  |  Branch (629:9): [True: 0, False: 490]
  ------------------
  630|      0|        return NULL;
  631|      0|    }
  632|       |
  633|    490|    za->src = src;
  634|    490|    za->open_flags = flags;
  635|    490|    za->flags = 0;
  636|    490|    za->ch_flags = 0;
  637|    490|    za->write_crc = NULL;
  638|       |
  639|    490|    if (flags & ZIP_RDONLY) {
  ------------------
  |  |   90|    490|#define ZIP_RDONLY 16
  ------------------
  |  Branch (639:9): [True: 0, False: 490]
  ------------------
  640|      0|        za->flags |= ZIP_AFL_RDONLY;
  ------------------
  |  |  113|      0|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  ------------------
  641|      0|        za->ch_flags |= ZIP_AFL_RDONLY;
  ------------------
  |  |  113|      0|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  ------------------
  642|      0|    }
  643|       |
  644|    490|    return za;
  645|    490|}
zip_open.c:_zip_file_exists:
  651|    490|static exists_t _zip_file_exists(zip_source_t *src, zip_error_t *error) {
  652|    490|    struct zip_stat st;
  653|       |
  654|    490|    zip_stat_init(&st);
  655|    490|    if (zip_source_stat(src, &st) != 0) {
  ------------------
  |  Branch (655:9): [True: 490, False: 0]
  ------------------
  656|    490|        zip_error_t *src_error = zip_source_error(src);
  657|    490|        if (zip_error_code_zip(src_error) == ZIP_ER_READ && zip_error_code_system(src_error) == ENOENT) {
  ------------------
  |  |  136|    980|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  |  Branch (657:13): [True: 490, False: 0]
  |  Branch (657:61): [True: 490, False: 0]
  ------------------
  658|    490|            return EXISTS_NOT;
  659|    490|        }
  660|      0|        _zip_error_copy(error, src_error);
  661|      0|        return EXISTS_ERROR;
  662|    490|    }
  663|       |
  664|      0|    return EXISTS_OK;
  665|    490|}

_zip_pkware_keys_reset:
   61|    490|void _zip_pkware_keys_reset(zip_pkware_keys_t *keys) {
   62|    490|    keys->key[0] = PKWARE_KEY0;
  ------------------
  |  |   40|    490|#define PKWARE_KEY0 305419896
  ------------------
   63|    490|    keys->key[1] = PKWARE_KEY1;
  ------------------
  |  |   41|    490|#define PKWARE_KEY1 591751049
  ------------------
   64|    490|    keys->key[2] = PKWARE_KEY2;
  ------------------
  |  |   42|    490|#define PKWARE_KEY2 878082192
  ------------------
   65|    490|}
_zip_pkware_encrypt:
   68|  11.7k|void _zip_pkware_encrypt(zip_pkware_keys_t *keys, zip_uint8_t *out, const zip_uint8_t *in, zip_uint64_t len) {
   69|  11.7k|    zip_uint64_t i;
   70|  11.7k|    zip_uint8_t b;
   71|  11.7k|    zip_uint8_t tmp;
   72|       |
   73|  85.2M|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (73:17): [True: 85.2M, False: 11.7k]
  ------------------
   74|  85.2M|        b = in[i];
   75|       |
   76|  85.2M|        if (out != NULL) {
  ------------------
  |  Branch (76:13): [True: 85.2M, False: 3.92k]
  ------------------
   77|  85.2M|            tmp = crypt_byte(keys);
   78|  85.2M|            update_keys(keys, b);
   79|  85.2M|            b ^= tmp;
   80|  85.2M|            out[i] = b;
   81|  85.2M|        }
   82|  3.92k|        else {
   83|       |            /* during initialization, we're only interested in key updates */
   84|  3.92k|            update_keys(keys, b);
   85|  3.92k|        }
   86|  85.2M|    }
   87|  11.7k|}
zip_pkware.c:crypt_byte:
   53|  85.2M|static zip_uint8_t crypt_byte(zip_pkware_keys_t *keys) {
   54|  85.2M|    zip_uint16_t tmp;
   55|  85.2M|    tmp = (zip_uint16_t)(keys->key[2] | 2);
   56|  85.2M|    tmp = (zip_uint16_t)(((zip_uint32_t)tmp * (tmp ^ 1)) >> 8);
   57|  85.2M|    return (zip_uint8_t)tmp;
   58|  85.2M|}
zip_pkware.c:update_keys:
   45|  85.2M|static void update_keys(zip_pkware_keys_t *keys, zip_uint8_t b) {
   46|  85.2M|    keys->key[0] = (zip_uint32_t)crc32(keys->key[0] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL;
   47|  85.2M|    keys->key[1] = (keys->key[1] + (keys->key[0] & 0xff)) * 134775813 + 1;
   48|  85.2M|    b = (zip_uint8_t)(keys->key[1] >> 24);
   49|  85.2M|    keys->key[2] = (zip_uint32_t)crc32(keys->key[2] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL;
   50|  85.2M|}

_zip_progress_end:
   67|    490|void _zip_progress_end(zip_progress_t *progress) {
   68|    490|    _zip_progress_update(progress, 1.0);
   69|    490|}
_zip_progress_free:
   72|    490|void _zip_progress_free(zip_progress_t *progress) {
   73|    490|    if (progress == NULL) {
  ------------------
  |  Branch (73:9): [True: 490, False: 0]
  ------------------
   74|    490|        return;
   75|    490|    }
   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_progress_start:
  143|    490|int _zip_progress_start(zip_progress_t *progress) {
  144|    490|    if (progress == NULL) {
  ------------------
  |  Branch (144:9): [True: 490, False: 0]
  ------------------
  145|    490|        return 0;
  146|    490|    }
  147|       |
  148|      0|    if (progress->callback_progress != NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 0]
  ------------------
  149|      0|        progress->last_update = 0.0;
  150|      0|        progress->callback_progress(progress->za, 0.0, progress->ud_progress);
  151|      0|    }
  152|       |
  153|      0|    if (progress->callback_cancel != NULL) {
  ------------------
  |  Branch (153:9): [True: 0, False: 0]
  ------------------
  154|      0|        if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
  ------------------
  |  Branch (154:13): [True: 0, False: 0]
  ------------------
  155|      0|            return -1;
  156|      0|        }
  157|      0|    }
  158|       |
  159|      0|    return 0;
  160|      0|}
_zip_progress_subrange:
  163|    490|int _zip_progress_subrange(zip_progress_t *progress, double start, double end) {
  164|    490|    if (progress == NULL) {
  ------------------
  |  Branch (164:9): [True: 490, False: 0]
  ------------------
  165|    490|        return 0;
  166|    490|    }
  167|       |
  168|      0|    progress->start = start;
  169|      0|    progress->end = end;
  170|       |
  171|      0|    return _zip_progress_update(progress, 0.0);
  172|    490|}
_zip_progress_update:
  174|    490|int _zip_progress_update(zip_progress_t *progress, double sub_current) {
  175|    490|    double current;
  176|       |
  177|    490|    if (progress == NULL) {
  ------------------
  |  Branch (177:9): [True: 490, False: 0]
  ------------------
  178|    490|        return 0;
  179|    490|    }
  180|       |
  181|      0|    if (progress->callback_progress != NULL) {
  ------------------
  |  Branch (181:9): [True: 0, False: 0]
  ------------------
  182|      0|        current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
  ------------------
  |  |  503|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 0, False: 0]
  |  |  |  Branch (503:25): [True: 0, False: 0]
  |  |  |  Branch (503:37): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  183|       |
  184|      0|        if (current - progress->last_update > progress->precision || (progress->last_update < 1 && current == 1)) {
  ------------------
  |  Branch (184:13): [True: 0, False: 0]
  |  Branch (184:71): [True: 0, False: 0]
  |  Branch (184:100): [True: 0, False: 0]
  ------------------
  185|      0|            progress->callback_progress(progress->za, current, progress->ud_progress);
  186|      0|            progress->last_update = current;
  187|      0|        }
  188|      0|    }
  189|       |
  190|      0|    if (progress->callback_cancel != NULL) {
  ------------------
  |  Branch (190:9): [True: 0, False: 0]
  ------------------
  191|      0|        if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  ------------------
  192|      0|            return -1;
  193|      0|        }
  194|      0|    }
  195|       |
  196|      0|    return 0;
  197|      0|}

zip_random_uint32:
   88|    490|zip_uint32_t zip_random_uint32(void) {
   89|    490|    static bool seeded = false;
   90|       |
   91|    490|    zip_uint32_t value;
   92|       |
   93|    490|    if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
  ------------------
  |  Branch (93:9): [True: 490, False: 0]
  ------------------
   94|    490|        return value;
   95|    490|    }
   96|       |
   97|      0|    if (!seeded) {
  ------------------
  |  Branch (97:9): [True: 0, False: 0]
  ------------------
   98|      0|        srandom((unsigned int)time(NULL));
  ------------------
  |  |   84|      0|#define srandom srand
  ------------------
   99|      0|        seeded = true;
  100|      0|    }
  101|       |
  102|      0|    return (zip_uint32_t)random();
  ------------------
  |  |   85|      0|#define random rand
  ------------------
  103|    490|}

zip_realloc:
   38|  1.47k|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|  1.47k|    zip_uint64_t new_alloced_elements;
   40|  1.47k|    void *new_memory;
   41|       |
   42|  1.47k|    if (additional_elements == 0) {
  ------------------
  |  Branch (42:9): [True: 0, False: 1.47k]
  ------------------
   43|      0|        return true;
   44|      0|    }
   45|       |
   46|  1.47k|    new_alloced_elements = *alloced_elements + additional_elements;
   47|       |
   48|  1.47k|    if (new_alloced_elements < additional_elements || new_alloced_elements > SIZE_MAX / element_size) {
  ------------------
  |  Branch (48:9): [True: 0, False: 1.47k]
  |  Branch (48:55): [True: 0, False: 1.47k]
  ------------------
   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|  1.47k|    if ((new_memory = realloc(*memory, (size_t)(new_alloced_elements * element_size))) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 1.47k]
  ------------------
   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|  1.47k|    *memory = new_memory;
   59|  1.47k|    *alloced_elements = new_alloced_elements;
   60|       |
   61|       |    return true;
   62|  1.47k|}

_zip_set_name:
   41|    490|int _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) {
   42|    490|    zip_entry_t *e;
   43|    490|    zip_string_t *str;
   44|    490|    bool same_as_orig;
   45|    490|    zip_int64_t i;
   46|    490|    const zip_uint8_t *old_name, *new_name;
   47|    490|    zip_string_t *old_str;
   48|       |
   49|    490|    if (idx >= za->nentry) {
  ------------------
  |  Branch (49:9): [True: 0, False: 490]
  ------------------
   50|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|    490|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  509|    490|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|    490|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (509:27): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   55|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   56|      0|        return -1;
   57|      0|    }
   58|       |
   59|    490|    if (name && name[0] != '\0') {
  ------------------
  |  Branch (59:9): [True: 490, False: 0]
  |  Branch (59:17): [True: 490, False: 0]
  ------------------
   60|       |        /* TODO: check for string too long */
   61|    490|        if ((str = _zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL) {
  ------------------
  |  Branch (61:13): [True: 0, False: 490]
  ------------------
   62|      0|            return -1;
   63|      0|        }
   64|    490|        if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) {
  ------------------
  |  |  264|    490|#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  101|    490|#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|    490|#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|    490|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  |  |  ------------------
  ------------------
                      if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) {
  ------------------
  |  |  101|    980|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (64:13): [True: 490, False: 0]
  |  Branch (64:66): [True: 0, False: 490]
  ------------------
   65|      0|            str->encoding = ZIP_ENCODING_UTF8_KNOWN;
   66|      0|        }
   67|    490|    }
   68|      0|    else {
   69|      0|        str = NULL;
   70|      0|    }
   71|       |
   72|       |    /* TODO: encoding flags needed for CP437? */
   73|    490|    if ((i = _zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) {
  ------------------
  |  Branch (73:9): [True: 0, False: 490]
  |  Branch (73:59): [True: 0, False: 0]
  ------------------
   74|      0|        _zip_string_free(str);
   75|      0|        zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
   76|      0|        return -1;
   77|      0|    }
   78|       |
   79|       |    /* no effective name change */
   80|    490|    if (i >= 0 && (zip_uint64_t)i == idx) {
  ------------------
  |  Branch (80:9): [True: 0, False: 490]
  |  Branch (80:19): [True: 0, False: 0]
  ------------------
   81|      0|        _zip_string_free(str);
   82|      0|        return 0;
   83|      0|    }
   84|       |
   85|    490|    e = za->entry + idx;
   86|       |
   87|    490|    if (e->orig) {
  ------------------
  |  Branch (87:9): [True: 0, False: 490]
  ------------------
   88|      0|        same_as_orig = _zip_string_equal(e->orig->filename, str);
   89|      0|    }
   90|    490|    else {
   91|    490|        same_as_orig = false;
   92|    490|    }
   93|       |
   94|    490|    if (!same_as_orig && e->changes == NULL) {
  ------------------
  |  Branch (94:9): [True: 490, False: 0]
  |  Branch (94:26): [True: 490, False: 0]
  ------------------
   95|    490|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (95:13): [True: 0, False: 490]
  ------------------
   96|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   97|      0|            _zip_string_free(str);
   98|      0|            return -1;
   99|      0|        }
  100|    490|    }
  101|       |
  102|    490|    if ((new_name = _zip_string_get(same_as_orig ? e->orig->filename : str, NULL, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (102:9): [True: 0, False: 490]
  |  Branch (102:37): [True: 0, False: 490]
  ------------------
  103|      0|        _zip_string_free(str);
  104|      0|        return -1;
  105|      0|    }
  106|       |
  107|    490|    if (e->changes) {
  ------------------
  |  Branch (107:9): [True: 490, False: 0]
  ------------------
  108|    490|        old_str = e->changes->filename;
  109|    490|    }
  110|      0|    else if (e->orig) {
  ------------------
  |  Branch (110:14): [True: 0, False: 0]
  ------------------
  111|      0|        old_str = e->orig->filename;
  112|      0|    }
  113|      0|    else {
  114|      0|        old_str = NULL;
  115|      0|    }
  116|       |
  117|    490|    if (old_str) {
  ------------------
  |  Branch (117:9): [True: 0, False: 490]
  ------------------
  118|      0|        if ((old_name = _zip_string_get(old_str, NULL, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (118:13): [True: 0, False: 0]
  ------------------
  119|      0|            _zip_string_free(str);
  120|      0|            return -1;
  121|      0|        }
  122|      0|    }
  123|    490|    else {
  124|    490|        old_name = NULL;
  125|    490|    }
  126|       |
  127|    490|    if (_zip_hash_add(za->names, new_name, idx, 0, &za->error) == false) {
  ------------------
  |  Branch (127:9): [True: 0, False: 490]
  ------------------
  128|      0|        _zip_string_free(str);
  129|      0|        return -1;
  130|      0|    }
  131|    490|    if (old_name) {
  ------------------
  |  Branch (131:9): [True: 0, False: 490]
  ------------------
  132|      0|        _zip_hash_delete(za->names, old_name, NULL);
  133|      0|    }
  134|       |
  135|    490|    if (same_as_orig) {
  ------------------
  |  Branch (135:9): [True: 0, False: 490]
  ------------------
  136|      0|        if (e->changes) {
  ------------------
  |  Branch (136:13): [True: 0, False: 0]
  ------------------
  137|      0|            if (e->changes->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  334|      0|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (137:17): [True: 0, False: 0]
  ------------------
  138|      0|                _zip_string_free(e->changes->filename);
  139|      0|                e->changes->changed &= ~ZIP_DIRENT_FILENAME;
  ------------------
  |  |  334|      0|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  140|      0|                if (e->changes->changed == 0) {
  ------------------
  |  Branch (140:21): [True: 0, False: 0]
  ------------------
  141|      0|                    _zip_dirent_free(e->changes);
  142|      0|                    e->changes = NULL;
  143|      0|                }
  144|      0|                else {
  145|       |                    /* TODO: what if not cloned? can that happen? */
  146|      0|                    e->changes->filename = e->orig->filename;
  147|      0|                }
  148|      0|            }
  149|      0|        }
  150|      0|        _zip_string_free(str);
  151|      0|    }
  152|    490|    else {
  153|    490|        if (e->changes->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  334|    490|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (153:13): [True: 0, False: 490]
  ------------------
  154|      0|            _zip_string_free(e->changes->filename);
  155|      0|        }
  156|    490|        e->changes->changed |= ZIP_DIRENT_FILENAME;
  ------------------
  |  |  334|    490|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  157|    490|        e->changes->filename = str;
  158|    490|    }
  159|       |
  160|    490|    return 0;
  161|    490|}

zip_source_begin_write:
   38|    490|ZIP_EXTERN int zip_source_begin_write(zip_source_t *src) {
   39|    490|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|    490|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|    490|    if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  433|    490|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  |  |  ------------------
  |  |  |  Branch (433:41): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   45|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|    490|    if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_BEGIN_WRITE) < 0) {
  ------------------
  |  Branch (49:9): [True: 0, False: 490]
  ------------------
   50|      0|        return -1;
   51|      0|    }
   52|       |
   53|    490|    src->write_state = ZIP_SOURCE_WRITE_OPEN;
   54|       |
   55|    490|    return 0;
   56|    490|}

zip_source_buffer:
   87|    490|ZIP_EXTERN zip_source_t *zip_source_buffer(zip_t *za, const void *data, zip_uint64_t len, int freep) {
   88|    490|    if (za == NULL) {
  ------------------
  |  Branch (88:9): [True: 0, False: 490]
  ------------------
   89|      0|        return NULL;
   90|      0|    }
   91|       |
   92|    490|    return zip_source_buffer_with_attributes_create(data, len, freep, NULL, &za->error);
   93|    490|}
zip_source_buffer_with_attributes_create:
  101|    490|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) {
  102|    490|    zip_buffer_fragment_t fragment;
  103|       |
  104|    490|    if (data == NULL) {
  ------------------
  |  Branch (104:9): [True: 0, False: 490]
  ------------------
  105|      0|        if (len > 0) {
  ------------------
  |  Branch (105:13): [True: 0, False: 0]
  ------------------
  106|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  107|      0|            return NULL;
  108|      0|        }
  109|       |
  110|      0|        return zip_source_buffer_fragment_with_attributes_create(NULL, 0, freep, attributes, error);
  111|      0|    }
  112|       |
  113|    490|    fragment.data = (zip_uint8_t *)data;
  114|    490|    fragment.length = len;
  115|       |
  116|    490|    return zip_source_buffer_fragment_with_attributes_create(&fragment, 1, freep, attributes, error);
  117|    490|}
zip_source_buffer_fragment_with_attributes_create:
  133|    490|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) {
  134|    490|    struct read_data *ctx;
  135|    490|    zip_source_t *zs;
  136|    490|    buffer_t *buffer;
  137|       |
  138|    490|    if (fragments == NULL && nfragments > 0) {
  ------------------
  |  Branch (138:9): [True: 0, False: 490]
  |  Branch (138:30): [True: 0, False: 0]
  ------------------
  139|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  140|      0|        return NULL;
  141|      0|    }
  142|       |
  143|    490|    if ((buffer = buffer_new(fragments, nfragments, freep, error)) == NULL) {
  ------------------
  |  Branch (143:9): [True: 0, False: 490]
  ------------------
  144|      0|        return NULL;
  145|      0|    }
  146|       |
  147|    490|    if ((ctx = (struct read_data *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (147:9): [True: 0, False: 490]
  ------------------
  148|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  149|      0|        buffer_free(buffer);
  150|      0|        return NULL;
  151|      0|    }
  152|       |
  153|    490|    ctx->in = buffer;
  154|    490|    ctx->out = NULL;
  155|    490|    ctx->mtime = time(NULL);
  156|    490|    if (attributes) {
  ------------------
  |  Branch (156:9): [True: 0, False: 490]
  ------------------
  157|      0|        (void)memcpy_s(&ctx->attributes, sizeof(ctx->attributes), attributes, sizeof(ctx->attributes));
  ------------------
  |  |  200|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  158|      0|    }
  159|    490|    else {
  160|    490|        zip_file_attributes_init(&ctx->attributes);
  161|    490|    }
  162|    490|    zip_error_init(&ctx->error);
  163|       |
  164|    490|    if ((zs = zip_source_function_create(read_data, ctx, error)) == NULL) {
  ------------------
  |  Branch (164:9): [True: 0, False: 490]
  ------------------
  165|      0|        buffer_free(ctx->in);
  166|      0|        free(ctx);
  167|      0|        return NULL;
  168|      0|    }
  169|       |
  170|    490|    return zs;
  171|    490|}
zip_source_buffer.c:read_data:
  178|  18.7k|static zip_int64_t read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  179|  18.7k|    struct read_data *ctx = (struct read_data *)state;
  180|       |
  181|  18.7k|    switch (cmd) {
  182|      0|    case ZIP_SOURCE_BEGIN_WRITE:
  ------------------
  |  Branch (182:5): [True: 0, False: 18.7k]
  ------------------
  183|      0|        if ((ctx->out = buffer_new(NULL, 0, 0, &ctx->error)) == NULL) {
  ------------------
  |  Branch (183:13): [True: 0, False: 0]
  ------------------
  184|      0|            return -1;
  185|      0|        }
  186|      0|        ctx->out->offset = 0;
  187|      0|        ctx->out->current_fragment = 0;
  188|      0|        return 0;
  189|       |
  190|      0|    case ZIP_SOURCE_BEGIN_WRITE_CLONING:
  ------------------
  |  Branch (190:5): [True: 0, False: 18.7k]
  ------------------
  191|      0|        if ((ctx->out = buffer_clone(ctx->in, len, &ctx->error)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  ------------------
  192|      0|            return -1;
  193|      0|        }
  194|      0|        ctx->out->offset = len;
  195|      0|        ctx->out->current_fragment = ctx->out->nfragments;
  196|      0|        return 0;
  197|       |
  198|    490|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (198:5): [True: 490, False: 18.2k]
  ------------------
  199|    490|        return 0;
  200|       |
  201|      0|    case ZIP_SOURCE_COMMIT_WRITE:
  ------------------
  |  Branch (201:5): [True: 0, False: 18.7k]
  ------------------
  202|      0|        buffer_free(ctx->in);
  203|      0|        ctx->in = ctx->out;
  204|      0|        ctx->out = NULL;
  205|      0|        return 0;
  206|       |
  207|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (207:5): [True: 0, False: 18.7k]
  ------------------
  208|      0|        return zip_error_to_data(&ctx->error, data, len);
  209|       |
  210|    490|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (210:5): [True: 490, False: 18.2k]
  ------------------
  211|    490|        buffer_free(ctx->in);
  212|    490|        buffer_free(ctx->out);
  213|    490|        free(ctx);
  214|    490|        return 0;
  215|       |
  216|  1.47k|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (216:5): [True: 1.47k, False: 17.2k]
  ------------------
  217|  1.47k|        if (len < sizeof(ctx->attributes)) {
  ------------------
  |  Branch (217:13): [True: 0, False: 1.47k]
  ------------------
  218|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  219|      0|            return -1;
  220|      0|        }
  221|       |
  222|  1.47k|        (void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
  ------------------
  |  |  200|  1.47k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  223|       |
  224|  1.47k|        return sizeof(ctx->attributes);
  225|  1.47k|    }
  226|       |
  227|    490|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (227:5): [True: 490, False: 18.2k]
  ------------------
  228|    490|        ctx->in->offset = 0;
  229|    490|        ctx->in->current_fragment = 0;
  230|    490|        return 0;
  231|       |
  232|  13.3k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (232:5): [True: 13.3k, False: 5.39k]
  ------------------
  233|  13.3k|        if (len > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  13.3k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (233:13): [True: 0, False: 13.3k]
  ------------------
  234|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  235|      0|            return -1;
  236|      0|        }
  237|  13.3k|        return buffer_read(ctx->in, data, len);
  238|       |
  239|      0|    case ZIP_SOURCE_REMOVE: {
  ------------------
  |  Branch (239:5): [True: 0, False: 18.7k]
  ------------------
  240|      0|        buffer_t *empty = buffer_new(NULL, 0, 0, &ctx->error);
  241|      0|        if (empty == NULL) {
  ------------------
  |  Branch (241:13): [True: 0, False: 0]
  ------------------
  242|      0|            return -1;
  243|      0|        }
  244|       |
  245|      0|        buffer_free(ctx->in);
  246|      0|        ctx->in = empty;
  247|      0|        return 0;
  248|      0|    }
  249|       |
  250|      0|    case ZIP_SOURCE_ROLLBACK_WRITE:
  ------------------
  |  Branch (250:5): [True: 0, False: 18.7k]
  ------------------
  251|      0|        buffer_free(ctx->out);
  252|      0|        ctx->out = NULL;
  253|      0|        return 0;
  254|       |
  255|      0|    case ZIP_SOURCE_SEEK:
  ------------------
  |  Branch (255:5): [True: 0, False: 18.7k]
  ------------------
  256|      0|        return buffer_seek(ctx->in, data, len, &ctx->error);
  257|       |
  258|      0|    case ZIP_SOURCE_SEEK_WRITE:
  ------------------
  |  Branch (258:5): [True: 0, False: 18.7k]
  ------------------
  259|      0|        return buffer_seek(ctx->out, data, len, &ctx->error);
  260|       |
  261|  1.96k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (261:5): [True: 1.96k, False: 16.7k]
  ------------------
  262|  1.96k|        zip_stat_t *st;
  263|       |
  264|  1.96k|        if (len < sizeof(*st)) {
  ------------------
  |  Branch (264:13): [True: 0, False: 1.96k]
  ------------------
  265|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  266|      0|            return -1;
  267|      0|        }
  268|       |
  269|  1.96k|        st = (zip_stat_t *)data;
  270|       |
  271|  1.96k|        zip_stat_init(st);
  272|  1.96k|        st->mtime = ctx->mtime;
  273|  1.96k|        st->size = ctx->in->size;
  274|  1.96k|        st->comp_size = st->size;
  275|  1.96k|        st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|  1.96k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  276|  1.96k|        st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  1.96k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  277|  1.96k|        st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|  1.96k|#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;
  ------------------
  |  |  324|  1.96k|#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;
  ------------------
  |  |  325|  1.96k|#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;
  ------------------
  |  |  328|  1.96k|#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;
  ------------------
  |  |  329|  1.96k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  278|       |
  279|  1.96k|        return sizeof(*st);
  280|  1.96k|    }
  281|       |
  282|    490|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (282:5): [True: 490, False: 18.2k]
  ------------------
  283|    490|        return zip_source_make_command_bitmap(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);
  284|       |
  285|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (285:5): [True: 0, False: 18.7k]
  ------------------
  286|      0|        if (ctx->in->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (286:13): [True: 0, False: 0]
  ------------------
  287|      0|            zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
  288|      0|            return -1;
  289|      0|        }
  290|      0|        return (zip_int64_t)ctx->in->offset;
  291|       |
  292|       |
  293|      0|    case ZIP_SOURCE_TELL_WRITE:
  ------------------
  |  Branch (293:5): [True: 0, False: 18.7k]
  ------------------
  294|      0|        if (ctx->out->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (294:13): [True: 0, False: 0]
  ------------------
  295|      0|            zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
  296|      0|            return -1;
  297|      0|        }
  298|      0|        return (zip_int64_t)ctx->out->offset;
  299|       |
  300|      0|    case ZIP_SOURCE_WRITE:
  ------------------
  |  Branch (300:5): [True: 0, False: 18.7k]
  ------------------
  301|      0|        if (len > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (301:13): [True: 0, False: 0]
  ------------------
  302|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  303|      0|            return -1;
  304|      0|        }
  305|      0|        return buffer_write(ctx->out, data, len, &ctx->error);
  306|       |
  307|      0|    default:
  ------------------
  |  Branch (307:5): [True: 0, False: 18.7k]
  ------------------
  308|      0|        zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
  309|      0|        return -1;
  310|  18.7k|    }
  311|  18.7k|}
zip_source_buffer.c:buffer_read:
  506|  13.3k|static zip_int64_t buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
  507|  13.3k|    zip_uint64_t n, i, fragment_offset;
  508|       |
  509|  13.3k|    length = ZIP_MIN(length, buffer->size - buffer->offset);
  ------------------
  |  |  503|  13.3k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 12.3k, False: 980]
  |  |  ------------------
  ------------------
  510|       |
  511|  13.3k|    if (length == 0) {
  ------------------
  |  Branch (511:9): [True: 490, False: 12.8k]
  ------------------
  512|    490|        return 0;
  513|    490|    }
  514|  12.8k|    if (length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  12.8k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (514:9): [True: 0, False: 12.8k]
  ------------------
  515|      0|        return -1;
  516|      0|    }
  517|       |
  518|  12.8k|    i = buffer->current_fragment;
  519|  12.8k|    fragment_offset = buffer->offset - buffer->fragment_offsets[i];
  520|  12.8k|    n = 0;
  521|  25.7k|    while (n < length) {
  ------------------
  |  Branch (521:12): [True: 12.8k, False: 12.8k]
  ------------------
  522|  12.8k|        zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
  ------------------
  |  |  503|  12.8k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 12.3k, False: 490]
  |  |  ------------------
  ------------------
  523|       |#if ZIP_UINT64_MAX > SIZE_MAX
  524|       |        left = ZIP_MIN(left, SIZE_MAX);
  525|       |#endif
  526|       |
  527|  12.8k|        (void)memcpy_s(data + n, (size_t)left, buffer->fragments[i].data + fragment_offset, (size_t)left);
  ------------------
  |  |  200|  12.8k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  528|       |
  529|  12.8k|        if (left == buffer->fragments[i].length - fragment_offset) {
  ------------------
  |  Branch (529:13): [True: 490, False: 12.3k]
  ------------------
  530|    490|            i++;
  531|    490|        }
  532|  12.8k|        n += left;
  533|  12.8k|        fragment_offset = 0;
  534|  12.8k|    }
  535|       |
  536|  12.8k|    buffer->offset += n;
  537|  12.8k|    buffer->current_fragment = i;
  538|  12.8k|    return (zip_int64_t)n;
  539|  12.8k|}
zip_source_buffer.c:buffer_grow_fragments:
  419|    490|static bool buffer_grow_fragments(buffer_t *buffer, zip_uint64_t capacity, zip_error_t *error) {
  420|    490|    zip_uint64_t additional_fragments;
  421|    490|    zip_uint64_t offset_capacity = buffer->fragments_capacity + 1;
  422|       |
  423|    490|    if (capacity <= buffer->fragments_capacity) {
  ------------------
  |  Branch (423:9): [True: 0, False: 490]
  ------------------
  424|      0|        return true;
  425|      0|    }
  426|       |
  427|    490|    additional_fragments = capacity - buffer->fragments_capacity;
  428|       |
  429|    490|    if (!ZIP_REALLOC(buffer->fragments, buffer->fragments_capacity, additional_fragments, error)) {
  ------------------
  |  |  107|    490|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (429:9): [True: 0, False: 490]
  ------------------
  430|      0|        return false;
  431|      0|    }
  432|       |    /* 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. */
  433|    490|    if (!ZIP_REALLOC(buffer->fragment_offsets, offset_capacity, additional_fragments, error)) {
  ------------------
  |  |  107|    490|#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: 490]
  ------------------
  434|      0|        buffer->fragments_capacity -= additional_fragments;
  435|      0|        return false;
  436|      0|    }
  437|       |
  438|    490|    return true;
  439|    490|}
zip_source_buffer.c:buffer_free:
  396|    980|static void buffer_free(buffer_t *buffer) {
  397|    980|    zip_uint64_t i;
  398|       |
  399|    980|    if (buffer == NULL) {
  ------------------
  |  Branch (399:9): [True: 490, False: 490]
  ------------------
  400|    490|        return;
  401|    490|    }
  402|       |
  403|    490|    if (buffer->shared_buffer != NULL) {
  ------------------
  |  Branch (403:9): [True: 0, False: 490]
  ------------------
  404|      0|        buffer->shared_buffer->shared_buffer = NULL;
  405|      0|        buffer->shared_buffer->shared_fragments = 0;
  406|       |
  407|      0|        buffer->first_owned_fragment = ZIP_MAX(buffer->first_owned_fragment, buffer->shared_fragments);
  ------------------
  |  |  502|      0|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (502:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  408|      0|    }
  409|       |
  410|    490|    for (i = buffer->first_owned_fragment; i < buffer->nfragments; i++) {
  ------------------
  |  Branch (410:44): [True: 0, False: 490]
  ------------------
  411|      0|        free(buffer->fragments[i].data);
  412|      0|    }
  413|    490|    free(buffer->fragments);
  414|    490|    free(buffer->fragment_offsets);
  415|    490|    free(buffer);
  416|    490|}
zip_source_buffer.c:buffer_new:
  442|    490|static buffer_t *buffer_new(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int free_data, zip_error_t *error) {
  443|    490|    buffer_t *buffer;
  444|       |
  445|    490|    if ((buffer = malloc(sizeof(*buffer))) == NULL) {
  ------------------
  |  Branch (445:9): [True: 0, False: 490]
  ------------------
  446|      0|        return NULL;
  447|      0|    }
  448|       |
  449|    490|    buffer->offset = 0;
  450|    490|    buffer->first_owned_fragment = 0;
  451|    490|    buffer->size = 0;
  452|    490|    buffer->fragments = NULL;
  453|    490|    buffer->fragment_offsets = NULL;
  454|    490|    buffer->nfragments = 0;
  455|    490|    buffer->fragments_capacity = 0;
  456|    490|    buffer->shared_buffer = NULL;
  457|    490|    buffer->shared_fragments = 0;
  458|       |
  459|    490|    if (nfragments == 0) {
  ------------------
  |  Branch (459:9): [True: 0, False: 490]
  ------------------
  460|      0|        if ((buffer->fragment_offsets = malloc(sizeof(buffer->fragment_offsets[0]))) == NULL) {
  ------------------
  |  Branch (460:13): [True: 0, False: 0]
  ------------------
  461|      0|            free(buffer);
  462|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  463|      0|            return NULL;
  464|      0|        }
  465|      0|        buffer->fragment_offsets[0] = 0;
  466|      0|    }
  467|    490|    else {
  468|    490|        zip_uint64_t i, j, offset;
  469|       |
  470|    490|        if (!buffer_grow_fragments(buffer, nfragments, NULL)) {
  ------------------
  |  Branch (470:13): [True: 0, False: 490]
  ------------------
  471|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  472|      0|            buffer_free(buffer);
  473|      0|            return NULL;
  474|      0|        }
  475|       |
  476|    490|        offset = 0;
  477|    980|        for (i = 0, j = 0; i < nfragments; i++) {
  ------------------
  |  Branch (477:28): [True: 490, False: 490]
  ------------------
  478|    490|            if (fragments[i].length == 0) {
  ------------------
  |  Branch (478:17): [True: 0, False: 490]
  ------------------
  479|      0|                continue;
  480|      0|            }
  481|    490|            if (fragments[i].data == NULL) {
  ------------------
  |  Branch (481:17): [True: 0, False: 490]
  ------------------
  482|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  483|      0|                buffer_free(buffer);
  484|      0|                return NULL;
  485|      0|            }
  486|    490|            buffer->fragments[j].data = fragments[i].data;
  487|    490|            buffer->fragments[j].length = fragments[i].length;
  488|    490|            buffer->fragment_offsets[j] = offset;
  489|    490|            if (offset + fragments[i].length < offset) {
  ------------------
  |  Branch (489:17): [True: 0, False: 490]
  ------------------
  490|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  491|      0|                buffer_free(buffer);
  492|      0|                return NULL;
  493|      0|            }
  494|    490|            offset += fragments[i].length;
  495|    490|            j++;
  496|    490|        }
  497|    490|        buffer->nfragments = j;
  498|    490|        buffer->first_owned_fragment = free_data ? 0 : buffer->nfragments;
  ------------------
  |  Branch (498:40): [True: 0, False: 490]
  ------------------
  499|    490|        buffer->fragment_offsets[buffer->nfragments] = offset;
  500|    490|        buffer->size = offset;
  501|    490|    }
  502|       |
  503|    490|    return buffer;
  504|    490|}

_zip_source_call:
   38|  85.3k|zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command) {
   39|  85.3k|    zip_int64_t ret;
   40|       |
   41|  85.3k|    if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) {
  ------------------
  |  |  275|  85.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (41:9): [True: 0, False: 85.3k]
  ------------------
   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|  85.3k|    if (src->src == NULL) {
  ------------------
  |  Branch (46:9): [True: 40.2k, False: 45.1k]
  ------------------
   47|  40.2k|        ret = src->cb.f(src->ud, data, length, command);
   48|  40.2k|    }
   49|  45.1k|    else {
   50|  45.1k|        ret = src->cb.l(src->src, src->ud, data, length, command);
   51|  45.1k|    }
   52|       |
   53|  85.3k|    if (ret < 0) {
  ------------------
  |  Branch (53:9): [True: 490, False: 84.8k]
  ------------------
   54|    490|        if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) {
  ------------------
  |  Branch (54:13): [True: 490, False: 0]
  |  Branch (54:44): [True: 490, False: 0]
  ------------------
   55|    490|            int e[2];
   56|       |
   57|    490|            if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) {
  ------------------
  |  Branch (57:17): [True: 0, False: 490]
  ------------------
   58|      0|                zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   59|      0|            }
   60|    490|            else {
   61|    490|                zip_error_set(&src->error, e[0], e[1]);
   62|    490|            }
   63|    490|        }
   64|    490|    }
   65|       |
   66|  85.3k|    return ret;
   67|  85.3k|}

zip_source_close:
   38|  2.45k|int zip_source_close(zip_source_t *src) {
   39|  2.45k|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  432|  2.45k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (39:9): [True: 490, False: 1.96k]
  ------------------
   40|    490|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|    490|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   41|    490|        return -1;
   42|    490|    }
   43|       |
   44|  1.96k|    src->open_count--;
   45|  1.96k|    if (src->open_count == 0) {
  ------------------
  |  Branch (45:9): [True: 1.96k, False: 0]
  ------------------
   46|  1.96k|        _zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE);
   47|       |
   48|  1.96k|        if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|  1.96k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 1.47k, False: 490]
  |  |  ------------------
  ------------------
   49|  1.47k|            if (zip_source_close(src->src) < 0) {
  ------------------
  |  Branch (49:17): [True: 0, False: 1.47k]
  ------------------
   50|      0|                zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   51|      0|            }
   52|  1.47k|        }
   53|  1.96k|    }
   54|       |
   55|  1.96k|    return 0;
   56|  2.45k|}

zip_source_commit_write:
   38|    490|ZIP_EXTERN int zip_source_commit_write(zip_source_t *src) {
   39|    490|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|    490|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|    490|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  433|    490|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
  |  Branch (44:9): [True: 0, False: 490]
  ------------------
   45|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|    490|    if (src->open_count > 1) {
  ------------------
  |  Branch (49:9): [True: 0, False: 490]
  ------------------
   50|      0|        zip_error_set(&src->error, ZIP_ER_INUSE, 0);
  ------------------
  |  |  160|      0|#define ZIP_ER_INUSE 29           /* N Resource still in use */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|    490|    else if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  432|    490|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (432:41): [True: 0, False: 490]
  |  |  ------------------
  ------------------
   54|      0|        if (zip_source_close(src) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 0]
  ------------------
   55|      0|            return -1;
   56|      0|        }
   57|      0|    }
   58|       |
   59|    490|    if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_COMMIT_WRITE) < 0) {
  ------------------
  |  Branch (59:9): [True: 0, False: 490]
  ------------------
   60|      0|        src->write_state = ZIP_SOURCE_WRITE_FAILED;
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|    490|    src->write_state = ZIP_SOURCE_WRITE_CLOSED;
   65|       |
   66|    490|    return 0;
   67|    490|}

_zip_get_compression_algorithm:
   93|    980|zip_compression_algorithm_t *_zip_get_compression_algorithm(zip_int32_t method, bool compress) {
   94|    980|    size_t i;
   95|    980|    zip_uint16_t real_method = ZIP_CM_ACTUAL(method);
  ------------------
  |  |   87|    980|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|    980|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    490|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 490, False: 490]
  |  |  ------------------
  ------------------
   96|       |
   97|    980|    for (i = 0; i < implementations_size; i++) {
  ------------------
  |  Branch (97:17): [True: 980, False: 0]
  ------------------
   98|    980|        if (implementations[i].method == real_method) {
  ------------------
  |  Branch (98:13): [True: 980, False: 0]
  ------------------
   99|    980|            if (compress) {
  ------------------
  |  Branch (99:17): [True: 980, False: 0]
  ------------------
  100|    980|                return implementations[i].compress;
  101|    980|            }
  102|      0|            else {
  103|      0|                return implementations[i].decompress;
  104|      0|            }
  105|    980|        }
  106|    980|    }
  107|       |
  108|      0|    return NULL;
  109|    980|}
zip_source_compress:
  118|    490|zip_source_t *zip_source_compress(zip_t *za, zip_source_t *src, zip_int32_t method, zip_uint32_t compression_flags) {
  119|       |    return compression_source_new(za, src, method, true, compression_flags);
  120|    490|}
zip_source_compress.c:compression_source_new:
  127|    490|static zip_source_t *compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, zip_uint32_t compression_flags) {
  128|    490|    struct context *ctx;
  129|    490|    zip_source_t *s2;
  130|    490|    zip_compression_algorithm_t *algorithm = NULL;
  131|       |
  132|    490|    if (src == NULL) {
  ------------------
  |  Branch (132:9): [True: 0, False: 490]
  ------------------
  133|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  134|      0|        return NULL;
  135|      0|    }
  136|       |
  137|    490|    if ((algorithm = _zip_get_compression_algorithm(method, compress)) == NULL) {
  ------------------
  |  Branch (137:9): [True: 0, False: 490]
  ------------------
  138|      0|        zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0);
  ------------------
  |  |  147|      0|#define ZIP_ER_COMPNOTSUPP 16     /* N Compression method not supported */
  ------------------
  139|      0|        return NULL;
  140|      0|    }
  141|       |
  142|    490|    if ((ctx = context_new(method, compress, compression_flags, algorithm, za->open_flags & ZIP_CHECKCONS)) == NULL) {
  ------------------
  |  |   88|    490|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (142:9): [True: 0, False: 490]
  ------------------
  143|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  144|      0|        return NULL;
  145|      0|    }
  146|       |
  147|    490|    if ((s2 = zip_source_layered(za, src, compress_callback, ctx)) == NULL) {
  ------------------
  |  Branch (147:9): [True: 0, False: 490]
  ------------------
  148|      0|        context_free(ctx);
  149|      0|        return NULL;
  150|      0|    }
  151|       |
  152|    490|    return s2;
  153|    490|}
zip_source_compress.c:context_new:
  156|    490|static struct context *context_new(zip_int32_t method, bool compress, zip_uint32_t compression_flags, zip_compression_algorithm_t *algorithm, bool check_consistency) {
  157|    490|    struct context *ctx;
  158|       |
  159|    490|    if ((ctx = (struct context *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (159:9): [True: 0, False: 490]
  ------------------
  160|      0|        return NULL;
  161|      0|    }
  162|    490|    zip_error_init(&ctx->error);
  163|    490|    ctx->can_store = compress ? method == ZIP_CM_DEFAULT : false;
  ------------------
  |  |  178|    490|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  |  Branch (163:22): [True: 490, False: 0]
  ------------------
  164|    490|    ctx->algorithm = algorithm;
  165|    490|    ctx->method = method;
  166|    490|    ctx->compress = compress;
  167|    490|    ctx->end_of_input = false;
  168|    490|    ctx->end_of_stream = false;
  169|    490|    ctx->is_stored = false;
  170|    490|    ctx->check_consistency = check_consistency;
  171|       |
  172|    490|    if ((ctx->ud = ctx->algorithm->allocate(ZIP_CM_ACTUAL(method), compression_flags, &ctx->error)) == NULL) {
  ------------------
  |  |   87|    490|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|    490|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    490|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 490, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (172:9): [True: 0, False: 490]
  ------------------
  173|      0|        zip_error_fini(&ctx->error);
  174|      0|        free(ctx);
  175|      0|        return NULL;
  176|      0|    }
  177|       |
  178|    490|    return ctx;
  179|    490|}
zip_source_compress.c:compress_callback:
  314|  15.1k|static zip_int64_t compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  315|  15.1k|    struct context *ctx;
  316|       |
  317|  15.1k|    ctx = (struct context *)ud;
  318|       |
  319|  15.1k|    switch (cmd) {
  320|    490|    case ZIP_SOURCE_OPEN: {
  ------------------
  |  Branch (320:5): [True: 490, False: 14.6k]
  ------------------
  321|    490|        zip_stat_t st;
  322|    490|        zip_file_attributes_t attributes;
  323|       |
  324|    490|        ctx->size = 0;
  325|    490|        ctx->end_of_input = false;
  326|    490|        ctx->end_of_stream = false;
  327|    490|        ctx->is_stored = false;
  328|    490|        ctx->first_read = -1;
  329|       |
  330|    490|        if (zip_source_stat(src, &st) < 0 || zip_source_get_file_attributes(src, &attributes) < 0) {
  ------------------
  |  Branch (330:13): [True: 0, False: 490]
  |  Branch (330:46): [True: 0, False: 490]
  ------------------
  331|      0|            zip_error_set_from_source(&ctx->error, src);
  332|      0|            return -1;
  333|      0|        }
  334|       |
  335|    490|        if (!ctx->algorithm->start(ctx->ud, &st, &attributes)) {
  ------------------
  |  Branch (335:13): [True: 0, False: 490]
  ------------------
  336|      0|            return -1;
  337|      0|        }
  338|       |
  339|    490|        return 0;
  340|    490|    }
  341|       |
  342|  11.2k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (342:5): [True: 11.2k, False: 3.92k]
  ------------------
  343|  11.2k|        return compress_read(src, ctx, data, len);
  344|       |
  345|    490|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (345:5): [True: 490, False: 14.6k]
  ------------------
  346|    490|        if (!ctx->algorithm->end(ctx->ud)) {
  ------------------
  |  Branch (346:13): [True: 0, False: 490]
  ------------------
  347|      0|            return -1;
  348|      0|        }
  349|    490|        return 0;
  350|       |
  351|    980|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (351:5): [True: 980, False: 14.1k]
  ------------------
  352|    980|        zip_stat_t *st;
  353|       |
  354|    980|        st = (zip_stat_t *)data;
  355|       |
  356|    980|        if (ctx->compress) {
  ------------------
  |  Branch (356:13): [True: 980, False: 0]
  ------------------
  357|    980|            if (ctx->end_of_stream) {
  ------------------
  |  Branch (357:17): [True: 490, False: 490]
  ------------------
  358|    490|                st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_ACTUAL(ctx->method);
  ------------------
  |  |  179|    131|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
                              st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_ACTUAL(ctx->method);
  ------------------
  |  |   87|    849|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|    359|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    359|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 359, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (358:35): [True: 131, False: 359]
  ------------------
  359|    490|                st->comp_size = ctx->size;
  360|    490|                st->valid |= ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  325|    490|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                              st->valid |= ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  328|    490|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  361|    490|            }
  362|    490|            else {
  363|    490|                st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  325|    490|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                              st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  328|    490|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  364|    490|            }
  365|    980|        }
  366|      0|        else {
  367|      0|            st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  368|      0|            st->valid |= ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  328|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  369|      0|            st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  325|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  370|      0|            if (ctx->end_of_stream) {
  ------------------
  |  Branch (370:17): [True: 0, False: 0]
  ------------------
  371|      0|                st->size = ctx->size;
  372|      0|                st->valid |= ZIP_STAT_SIZE;
  ------------------
  |  |  324|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  373|      0|            }
  374|      0|        }
  375|    980|    }
  376|    980|        return 0;
  377|       |
  378|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (378:5): [True: 0, False: 15.1k]
  ------------------
  379|      0|        return zip_error_to_data(&ctx->error, data, len);
  380|       |
  381|    490|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (381:5): [True: 490, False: 14.6k]
  ------------------
  382|    490|        context_free(ctx);
  383|    490|        return 0;
  384|       |
  385|    980|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (385:5): [True: 980, False: 14.1k]
  ------------------
  386|    980|        zip_file_attributes_t *attributes = (zip_file_attributes_t *)data;
  387|       |
  388|    980|        if (len < sizeof(*attributes)) {
  ------------------
  |  Branch (388:13): [True: 0, False: 980]
  ------------------
  389|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  390|      0|            return -1;
  391|      0|        }
  392|       |
  393|    980|        attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  363|    980|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
                      attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  365|    980|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  394|    980|        attributes->version_needed = ctx->algorithm->version_needed;
  395|    980|        attributes->general_purpose_bit_mask = ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK;
  ------------------
  |  |  102|    980|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK 0x083e
  ------------------
  396|    980|        attributes->general_purpose_bit_flags = (ctx->is_stored ? 0 : ctx->algorithm->general_purpose_bit_flags(ctx->ud));
  ------------------
  |  Branch (396:50): [True: 131, False: 849]
  ------------------
  397|       |
  398|    980|        return sizeof(*attributes);
  399|    980|    }
  400|       |
  401|    490|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (401:5): [True: 490, False: 14.6k]
  ------------------
  402|    490|        return ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  ------------------
  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  403|       |
  404|      0|    default:
  ------------------
  |  Branch (404:5): [True: 0, False: 15.1k]
  ------------------
  405|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  406|  15.1k|    }
  407|  15.1k|}
zip_source_compress.c:compress_read:
  194|  11.2k|static zip_int64_t compress_read(zip_source_t *src, struct context *ctx, void *data, zip_uint64_t len) {
  195|  11.2k|    zip_compression_status_t ret;
  196|  11.2k|    bool end;
  197|  11.2k|    zip_int64_t n;
  198|  11.2k|    zip_uint64_t out_offset;
  199|  11.2k|    zip_uint64_t out_len;
  200|       |
  201|  11.2k|    if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) {
  ------------------
  |  |  131|  11.2k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
  |  Branch (201:9): [True: 0, False: 11.2k]
  ------------------
  202|      0|        return -1;
  203|      0|    }
  204|       |
  205|  11.2k|    if (len == 0 || ctx->end_of_stream) {
  ------------------
  |  Branch (205:9): [True: 0, False: 11.2k]
  |  Branch (205:21): [True: 469, False: 10.7k]
  ------------------
  206|    469|        return 0;
  207|    469|    }
  208|       |
  209|  10.7k|    out_offset = 0;
  210|       |
  211|  10.7k|    end = false;
  212|  48.0k|    while (!end && out_offset < len) {
  ------------------
  |  Branch (212:12): [True: 47.7k, False: 359]
  |  Branch (212:20): [True: 37.4k, False: 10.2k]
  ------------------
  213|  37.4k|        out_len = len - out_offset;
  214|  37.4k|        ret = ctx->algorithm->process(ctx->ud, (zip_uint8_t *)data + out_offset, &out_len);
  215|       |
  216|  37.4k|        if (ret != ZIP_COMPRESSION_ERROR) {
  ------------------
  |  Branch (216:13): [True: 37.4k, False: 0]
  ------------------
  217|  37.4k|            out_offset += out_len;
  218|  37.4k|        }
  219|       |
  220|  37.4k|        switch (ret) {
  ------------------
  |  Branch (220:17): [True: 37.4k, False: 0]
  ------------------
  221|    490|        case ZIP_COMPRESSION_END:
  ------------------
  |  Branch (221:9): [True: 490, False: 36.9k]
  ------------------
  222|    490|            ctx->end_of_stream = true;
  223|       |
  224|    490|            if (!ctx->end_of_input) {
  ------------------
  |  Branch (224:17): [True: 0, False: 490]
  ------------------
  225|      0|                n = zip_source_read(src, ctx->buffer, 1);
  226|      0|                if (n < 0) {
  ------------------
  |  Branch (226:21): [True: 0, False: 0]
  ------------------
  227|      0|                    zip_error_set_from_source(&ctx->error, src);
  228|      0|                    end = true;
  229|      0|                    break;
  230|      0|                }
  231|      0|                else if (n == 0) {
  ------------------
  |  Branch (231:26): [True: 0, False: 0]
  ------------------
  232|      0|                    ctx->end_of_input = true;
  233|      0|                    n = ctx->algorithm->end_of_input(ctx->ud) ? 1 : 0;
  ------------------
  |  Branch (233:25): [True: 0, False: 0]
  ------------------
  234|      0|                }
  235|       |
  236|      0|                if (n > 0 && ctx->check_consistency) {
  ------------------
  |  Branch (236:21): [True: 0, False: 0]
  |  Branch (236:30): [True: 0, False: 0]
  ------------------
  237|       |                    /* garbage after stream, or compression ended before all data read */
  238|      0|                    zip_error_set(&ctx->error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                                  zip_error_set(&ctx->error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE);
  ------------------
  |  |  246|      0|#define ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE 25 /* G garbage at end of compressed data */
  ------------------
  239|      0|                    end = true;
  240|      0|                    break;
  241|      0|                }
  242|      0|            }
  243|       |
  244|    490|            if (ctx->first_read < 0) {
  ------------------
  |  Branch (244:17): [True: 0, False: 490]
  ------------------
  245|       |                /* we got end of processed stream before reading any input data */
  246|      0|                zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  247|      0|                end = true;
  248|      0|                break;
  249|      0|            }
  250|    490|            if (ctx->can_store && (zip_uint64_t)ctx->first_read <= out_offset) {
  ------------------
  |  Branch (250:17): [True: 235, False: 255]
  |  Branch (250:35): [True: 131, False: 104]
  ------------------
  251|    131|                ctx->is_stored = true;
  252|    131|                ctx->size = (zip_uint64_t)ctx->first_read;
  253|    131|                (void)memcpy_s(data, ctx->size, ctx->buffer, ctx->size);
  ------------------
  |  |  200|    131|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  254|    131|                return (zip_int64_t)ctx->size;
  255|    131|            }
  256|    359|            end = true;
  257|    359|            break;
  258|       |
  259|  23.6k|        case ZIP_COMPRESSION_OK:
  ------------------
  |  Branch (259:9): [True: 23.6k, False: 13.8k]
  ------------------
  260|  23.6k|            break;
  261|       |
  262|  13.3k|        case ZIP_COMPRESSION_NEED_DATA:
  ------------------
  |  Branch (262:9): [True: 13.3k, False: 24.1k]
  ------------------
  263|  13.3k|            if (ctx->end_of_input) {
  ------------------
  |  Branch (263:17): [True: 0, False: 13.3k]
  ------------------
  264|       |                /* TODO: error: stream not ended, but no more input */
  265|      0|                end = true;
  266|      0|                break;
  267|      0|            }
  268|       |
  269|  13.3k|            if ((n = zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) {
  ------------------
  |  Branch (269:17): [True: 0, False: 13.3k]
  ------------------
  270|      0|                zip_error_set_from_source(&ctx->error, src);
  271|      0|                end = true;
  272|      0|                break;
  273|      0|            }
  274|  13.3k|            else if (n == 0) {
  ------------------
  |  Branch (274:22): [True: 490, False: 12.8k]
  ------------------
  275|    490|                ctx->end_of_input = true;
  276|    490|                ctx->algorithm->end_of_input(ctx->ud);
  277|    490|                if (ctx->first_read < 0) {
  ------------------
  |  Branch (277:21): [True: 0, False: 490]
  ------------------
  278|      0|                    ctx->first_read = 0;
  279|      0|                }
  280|    490|            }
  281|  12.8k|            else {
  282|  12.8k|                if (ctx->first_read >= 0) {
  ------------------
  |  Branch (282:21): [True: 12.3k, False: 490]
  ------------------
  283|       |                    /* we overwrote a previously filled ctx->buffer */
  284|  12.3k|                    ctx->can_store = false;
  285|  12.3k|                }
  286|    490|                else {
  287|    490|                    ctx->first_read = n;
  288|    490|                }
  289|       |
  290|  12.8k|                ctx->algorithm->input(ctx->ud, ctx->buffer, (zip_uint64_t)n);
  291|  12.8k|            }
  292|  13.3k|            break;
  293|       |
  294|  13.3k|        case ZIP_COMPRESSION_ERROR:
  ------------------
  |  Branch (294:9): [True: 0, False: 37.4k]
  ------------------
  295|       |            /* error set by algorithm */
  296|      0|            if (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) {
  ------------------
  |  |  131|      0|#define ZIP_ER_OK 0               /* N No error */
  ------------------
  |  Branch (296:17): [True: 0, False: 0]
  ------------------
  297|      0|                zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  298|      0|            }
  299|      0|            end = true;
  300|      0|            break;
  301|  37.4k|        }
  302|  37.4k|    }
  303|       |
  304|  10.6k|    if (out_offset > 0) {
  ------------------
  |  Branch (304:9): [True: 10.6k, False: 21]
  ------------------
  305|  10.6k|        ctx->can_store = false;
  306|  10.6k|        ctx->size += out_offset;
  307|  10.6k|        return (zip_int64_t)out_offset;
  308|  10.6k|    }
  309|       |
  310|     21|    return (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) ? 0 : -1;
  ------------------
  |  |  131|     21|#define ZIP_ER_OK 0               /* N No error */
  ------------------
  |  Branch (310:12): [True: 21, False: 0]
  ------------------
  311|  10.6k|}
zip_source_compress.c:context_free:
  182|    490|static void context_free(struct context *ctx) {
  183|    490|    if (ctx == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 490]
  ------------------
  184|      0|        return;
  185|      0|    }
  186|       |
  187|    490|    ctx->algorithm->deallocate(ctx->ud);
  188|    490|    zip_error_fini(&ctx->error);
  189|       |
  190|    490|    free(ctx);
  191|    490|}

zip_source_crc_create:
   54|    490|zip_source_t *zip_source_crc_create(zip_source_t *src, int validate, zip_error_t *error) {
   55|    490|    struct crc_context *ctx;
   56|    490|    zip_source_t *new_src;
   57|       |
   58|    490|    if (src == NULL) {
  ------------------
  |  Branch (58:9): [True: 0, False: 490]
  ------------------
   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|    490|    if ((ctx = (struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (63:9): [True: 0, False: 490]
  ------------------
   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|    490|    zip_error_init(&ctx->error);
   69|    490|    ctx->validate = validate;
   70|    490|    ctx->crc_complete = 0;
   71|    490|    ctx->crc_position = 0;
   72|    490|    ctx->crc = (zip_uint32_t)crc32(0, NULL, 0);
   73|    490|    ctx->size = 0;
   74|       |
   75|    490|    new_src = zip_source_layered_create(src, crc_read, ctx, error);
   76|    490|    if (new_src == NULL) {
  ------------------
  |  Branch (76:9): [True: 0, False: 490]
  ------------------
   77|      0|        free(ctx);
   78|      0|        return NULL;
   79|      0|    }
   80|    490|    return new_src;
   81|    490|}
zip_source_crc.c:crc_read:
   84|  16.7k|static zip_int64_t crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
   85|  16.7k|    struct crc_context *ctx;
   86|  16.7k|    zip_int64_t n;
   87|       |
   88|  16.7k|    ctx = (struct crc_context *)_ctx;
   89|       |
   90|  16.7k|    switch (cmd) {
   91|    490|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (91:5): [True: 490, False: 16.2k]
  ------------------
   92|    490|        ctx->position = 0;
   93|    490|        return 0;
   94|       |
   95|  13.3k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (95:5): [True: 13.3k, False: 3.43k]
  ------------------
   96|  13.3k|        if ((n = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (96:13): [True: 0, False: 13.3k]
  ------------------
   97|      0|            zip_error_set_from_source(&ctx->error, src);
   98|      0|            return -1;
   99|      0|        }
  100|       |
  101|  13.3k|        if (n == 0) {
  ------------------
  |  Branch (101:13): [True: 490, False: 12.8k]
  ------------------
  102|    490|            if (ctx->crc_position == ctx->position) {
  ------------------
  |  Branch (102:17): [True: 490, False: 0]
  ------------------
  103|    490|                ctx->crc_complete = 1;
  104|    490|                ctx->size = ctx->position;
  105|       |
  106|    490|                if (ctx->validate) {
  ------------------
  |  Branch (106:21): [True: 0, False: 490]
  ------------------
  107|      0|                    struct zip_stat st;
  108|       |
  109|      0|                    if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (109:25): [True: 0, False: 0]
  ------------------
  110|      0|                        zip_error_set_from_source(&ctx->error, src);
  111|      0|                        return -1;
  112|      0|                    }
  113|       |
  114|      0|                    if ((st.valid & ZIP_STAT_CRC) && st.crc != ctx->crc) {
  ------------------
  |  |  327|      0|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (114:25): [True: 0, False: 0]
  |  Branch (114:54): [True: 0, False: 0]
  ------------------
  115|      0|                        zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
  ------------------
  |  |  138|      0|#define ZIP_ER_CRC 7              /* N CRC error */
  ------------------
  116|      0|                        return -1;
  117|      0|                    }
  118|      0|                    if ((st.valid & ZIP_STAT_SIZE) && st.size != ctx->size) {
  ------------------
  |  |  324|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (118:25): [True: 0, False: 0]
  |  Branch (118:55): [True: 0, False: 0]
  ------------------
  119|       |                        /* We don't have the index here, but the caller should know which file they are reading from. */
  120|      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]
  |  |  ------------------
  ------------------
  121|      0|                        return -1;
  122|      0|                    }
  123|      0|                }
  124|    490|            }
  125|    490|        }
  126|  12.8k|        else if (!ctx->crc_complete && ctx->position <= ctx->crc_position) {
  ------------------
  |  Branch (126:18): [True: 12.8k, False: 0]
  |  Branch (126:40): [True: 12.8k, False: 0]
  ------------------
  127|  12.8k|            zip_uint64_t i, nn;
  128|       |
  129|  25.7k|            for (i = ctx->crc_position - ctx->position; i < (zip_uint64_t)n; i += nn) {
  ------------------
  |  Branch (129:57): [True: 12.8k, False: 12.8k]
  ------------------
  130|  12.8k|                nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n - i);
  ------------------
  |  |  503|  12.8k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 0, False: 12.8k]
  |  |  ------------------
  ------------------
  131|       |
  132|  12.8k|                ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data + i, (uInt)nn);
  133|  12.8k|                ctx->crc_position += nn;
  134|  12.8k|            }
  135|  12.8k|        }
  136|  13.3k|        ctx->position += (zip_uint64_t)n;
  137|  13.3k|        return n;
  138|       |
  139|    490|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (139:5): [True: 490, False: 16.2k]
  ------------------
  140|    490|        return 0;
  141|       |
  142|  1.47k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (142:5): [True: 1.47k, False: 15.3k]
  ------------------
  143|  1.47k|        zip_stat_t *st;
  144|       |
  145|  1.47k|        st = (zip_stat_t *)data;
  146|       |
  147|  1.47k|        if (ctx->crc_complete) {
  ------------------
  |  Branch (147:13): [True: 490, False: 980]
  ------------------
  148|    490|            if ((st->valid & ZIP_STAT_SIZE) && st->size != ctx->size) {
  ------------------
  |  |  324|    490|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (148:17): [True: 490, False: 0]
  |  Branch (148:48): [True: 0, False: 490]
  ------------------
  149|      0|                zip_error_set(&ctx->error, ZIP_ER_DATA_LENGTH, 0);
  ------------------
  |  |  164|      0|#define ZIP_ER_DATA_LENGTH 33     /* N Unexpected length of data */
  ------------------
  150|      0|                return -1;
  151|      0|            }
  152|       |            /* TODO: Set comp_size, comp_method, encryption_method?
  153|       |                    After all, this only works for uncompressed data. */
  154|    490|            st->size = ctx->size;
  155|    490|            st->crc = ctx->crc;
  156|    490|            st->comp_size = ctx->size;
  157|    490|            st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|    490|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  158|    490|            st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|    490|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  159|    490|            st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  324|    490|#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;
  ------------------
  |  |  327|    490|#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;
  ------------------
  |  |  325|    490|#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;
  ------------------
  |  |  328|    490|#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;
  ------------------
  |  |  329|    490|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  160|    490|        }
  161|  1.47k|        return 0;
  162|  1.47k|    }
  163|       |
  164|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (164:5): [True: 0, False: 16.7k]
  ------------------
  165|      0|        return zip_error_to_data(&ctx->error, data, len);
  166|       |
  167|    490|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (167:5): [True: 490, False: 16.2k]
  ------------------
  168|    490|        free(ctx);
  169|    490|        return 0;
  170|       |
  171|    490|    case ZIP_SOURCE_SUPPORTS: {
  ------------------
  |  Branch (171:5): [True: 490, False: 16.2k]
  ------------------
  172|    490|        zip_int64_t mask = zip_source_supports(src);
  173|       |
  174|    490|        if (mask < 0) {
  ------------------
  |  Branch (174:13): [True: 0, False: 490]
  ------------------
  175|      0|            zip_error_set_from_source(&ctx->error, src);
  176|      0|            return -1;
  177|      0|        }
  178|       |
  179|    490|        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);
  180|    490|        mask |= zip_source_make_command_bitmap(ZIP_SOURCE_FREE, -1);
  181|    490|        return mask;
  182|    490|    }
  183|       |
  184|      0|    case ZIP_SOURCE_SEEK: {
  ------------------
  |  Branch (184:5): [True: 0, False: 16.7k]
  ------------------
  185|      0|        zip_int64_t new_position;
  186|      0|        zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
  ------------------
  |  |  311|      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 (311:54): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  187|       |
  188|      0|        if (args == NULL) {
  ------------------
  |  Branch (188:13): [True: 0, False: 0]
  ------------------
  189|      0|            return -1;
  190|      0|        }
  191|      0|        if (zip_source_seek(src, args->offset, args->whence) < 0 || (new_position = zip_source_tell(src)) < 0) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  |  Branch (191:69): [True: 0, False: 0]
  ------------------
  192|      0|            zip_error_set_from_source(&ctx->error, src);
  193|      0|            return -1;
  194|      0|        }
  195|       |
  196|      0|        ctx->position = (zip_uint64_t)new_position;
  197|       |
  198|      0|        return 0;
  199|      0|    }
  200|       |
  201|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (201:5): [True: 0, False: 16.7k]
  ------------------
  202|      0|        return (zip_int64_t)ctx->position;
  203|       |
  204|      0|    default:
  ------------------
  |  Branch (204:5): [True: 0, False: 16.7k]
  ------------------
  205|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  206|  16.7k|    }
  207|  16.7k|}

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

zip_source_file_common_new:
   51|    490|zip_source_t *zip_source_file_common_new(const char *fname, void *file, zip_uint64_t start, zip_int64_t len, const zip_stat_t *st, zip_source_file_operations_t *ops, void *ops_userdata, zip_error_t *error) {
   52|    490|    zip_source_file_context_t *ctx;
   53|    490|    zip_source_t *zs;
   54|    490|    zip_source_file_stat_t sb;
   55|    490|    zip_uint64_t length;
   56|       |
   57|    490|    if (ops == NULL) {
  ------------------
  |  Branch (57:9): [True: 0, False: 490]
  ------------------
   58|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   59|      0|        return NULL;
   60|      0|    }
   61|       |
   62|    490|    if (ops->close == NULL || ops->read == NULL || ops->seek == NULL || ops->stat == NULL) {
  ------------------
  |  Branch (62:9): [True: 0, False: 490]
  |  Branch (62:31): [True: 0, False: 490]
  |  Branch (62:52): [True: 0, False: 490]
  |  Branch (62:73): [True: 0, False: 490]
  ------------------
   63|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   64|      0|        return NULL;
   65|      0|    }
   66|       |
   67|    490|    if (ops->write != NULL && (ops->commit_write == NULL || ops->create_temp_output == NULL || ops->remove == NULL || ops->rollback_write == NULL || ops->tell == NULL)) {
  ------------------
  |  Branch (67:9): [True: 490, False: 0]
  |  Branch (67:32): [True: 0, False: 490]
  |  Branch (67:61): [True: 0, False: 490]
  |  Branch (67:96): [True: 0, False: 490]
  |  Branch (67:119): [True: 0, False: 490]
  |  Branch (67:150): [True: 0, False: 490]
  ------------------
   68|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   69|      0|        return NULL;
   70|      0|    }
   71|       |
   72|    490|    if (fname != NULL) {
  ------------------
  |  Branch (72:9): [True: 490, False: 0]
  ------------------
   73|    490|        if (ops->open == NULL || ops->string_duplicate == NULL) {
  ------------------
  |  Branch (73:13): [True: 0, False: 490]
  |  Branch (73:34): [True: 0, False: 490]
  ------------------
   74|      0|            zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   75|      0|            return NULL;
   76|      0|        }
   77|    490|    }
   78|      0|    else if (file == NULL) {
  ------------------
  |  Branch (78:14): [True: 0, False: 0]
  ------------------
   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|       |
   83|    490|    if (len < 0) {
  ------------------
  |  Branch (83:9): [True: 490, False: 0]
  ------------------
   84|    490|        if (len == -1) {
  ------------------
  |  Branch (84:13): [True: 490, False: 0]
  ------------------
   85|    490|            len = ZIP_LENGTH_TO_END;
  ------------------
  |  |  126|    490|#define ZIP_LENGTH_TO_END 0
  ------------------
   86|    490|        }
   87|       |        // TODO: return ZIP_ER_INVAL if len != ZIP_LENGTH_UNCHECKED?
   88|    490|        length = 0;
   89|    490|    }
   90|      0|    else {
   91|      0|        length = (zip_uint64_t)len;
   92|      0|    }
   93|       |
   94|    490|    if (start > ZIP_INT64_MAX || start + length < start) {
  ------------------
  |  |   45|    980|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (94:9): [True: 0, False: 490]
  |  Branch (94:34): [True: 0, False: 490]
  ------------------
   95|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   96|      0|        return NULL;
   97|      0|    }
   98|       |
   99|    490|    if ((ctx = (zip_source_file_context_t *)malloc(sizeof(zip_source_file_context_t))) == NULL) {
  ------------------
  |  Branch (99:9): [True: 0, False: 490]
  ------------------
  100|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  101|      0|        return NULL;
  102|      0|    }
  103|       |
  104|    490|    ctx->ops = ops;
  105|    490|    ctx->ops_userdata = ops_userdata;
  106|    490|    ctx->fname = NULL;
  107|    490|    if (fname) {
  ------------------
  |  Branch (107:9): [True: 490, False: 0]
  ------------------
  108|    490|        if ((ctx->fname = ops->string_duplicate(ctx, fname)) == NULL) {
  ------------------
  |  Branch (108:13): [True: 0, False: 490]
  ------------------
  109|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  110|      0|            free(ctx);
  111|      0|            return NULL;
  112|      0|        }
  113|    490|    }
  114|    490|    ctx->f = file;
  115|    490|    ctx->start = start;
  116|    490|    ctx->len = length;
  117|    490|    if (st) {
  ------------------
  |  Branch (117:9): [True: 0, False: 490]
  ------------------
  118|      0|        (void)memcpy_s(&ctx->st, sizeof(ctx->st), st, sizeof(*st));
  ------------------
  |  |  200|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  119|      0|        ctx->st.name = NULL;
  120|      0|        ctx->st.valid &= ~ZIP_STAT_NAME;
  ------------------
  |  |  322|      0|#define ZIP_STAT_NAME 0x0001u
  ------------------
  121|      0|    }
  122|    490|    else {
  123|    490|        zip_stat_init(&ctx->st);
  124|    490|    }
  125|       |
  126|    490|    if (ctx->len > 0) {
  ------------------
  |  Branch (126:9): [True: 0, False: 490]
  ------------------
  127|      0|        ctx->st.size = ctx->len;
  128|      0|        ctx->st.valid |= ZIP_STAT_SIZE;
  ------------------
  |  |  324|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  129|      0|    }
  130|       |
  131|    490|    zip_error_init(&ctx->stat_error);
  132|       |
  133|    490|    ctx->tmpname = NULL;
  134|    490|    ctx->fout = NULL;
  135|       |
  136|    490|    zip_error_init(&ctx->error);
  137|    490|    zip_file_attributes_init(&ctx->attributes);
  138|       |
  139|    490|    ctx->supports = ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  ------------------
  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  140|       |
  141|    490|    zip_source_file_stat_init(&sb);
  142|    490|    if (!ops->stat(ctx, &sb)) {
  ------------------
  |  Branch (142:9): [True: 0, False: 490]
  ------------------
  143|      0|        _zip_error_copy(error, &ctx->error);
  144|      0|        free(ctx->fname);
  145|      0|        free(ctx);
  146|      0|        return NULL;
  147|      0|    }
  148|       |
  149|    490|    if (!sb.exists) {
  ------------------
  |  Branch (149:9): [True: 490, False: 0]
  ------------------
  150|    490|        if (ctx->fname && ctx->start == 0 && ctx->len == 0 && ops->write != NULL) {
  ------------------
  |  Branch (150:13): [True: 490, False: 0]
  |  Branch (150:27): [True: 490, False: 0]
  |  Branch (150:46): [True: 490, False: 0]
  |  Branch (150:63): [True: 490, False: 0]
  ------------------
  151|    490|            ctx->supports = ZIP_SOURCE_SUPPORTS_WRITABLE;
  ------------------
  |  |  293|    490|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  288|    490|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  281|    490|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  282|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  289|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  290|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  294|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  295|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|    490|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  152|       |            /* zip_open_from_source checks for this to detect non-existing files */
  153|    490|            zip_error_set(&ctx->stat_error, ZIP_ER_READ, ENOENT);
  ------------------
  |  |  136|    490|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  154|    490|        }
  155|      0|        else {
  156|      0|            zip_error_set(&ctx->stat_error, ZIP_ER_READ, ENOENT);
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  157|      0|            free(ctx->fname);
  158|      0|            free(ctx);
  159|      0|            return NULL;
  160|      0|        }
  161|    490|    }
  162|      0|    else {
  163|      0|        if ((ctx->st.valid & ZIP_STAT_MTIME) == 0) {
  ------------------
  |  |  326|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (163:13): [True: 0, False: 0]
  ------------------
  164|      0|            ctx->st.mtime = sb.mtime;
  165|      0|            ctx->st.valid |= ZIP_STAT_MTIME;
  ------------------
  |  |  326|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  166|      0|        }
  167|      0|        if (sb.regular_file) {
  ------------------
  |  Branch (167:13): [True: 0, False: 0]
  ------------------
  168|      0|            ctx->supports = ZIP_SOURCE_SUPPORTS_SEEKABLE;
  ------------------
  |  |  288|      0|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  281|      0|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  282|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  289|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  290|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  169|       |
  170|      0|            if (ctx->start + ctx->len > sb.size) {
  ------------------
  |  Branch (170:17): [True: 0, False: 0]
  ------------------
  171|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  172|      0|                free(ctx->fname);
  173|      0|                free(ctx);
  174|      0|                return NULL;
  175|      0|            }
  176|       |
  177|      0|            if (ctx->len == 0) {
  ------------------
  |  Branch (177:17): [True: 0, False: 0]
  ------------------
  178|      0|                if (len != ZIP_LENGTH_UNCHECKED) {
  ------------------
  |  |  127|      0|#define ZIP_LENGTH_UNCHECKED (-2) /* only supported by zip_source_file and its variants */
  ------------------
  |  Branch (178:21): [True: 0, False: 0]
  ------------------
  179|      0|                    ctx->len = sb.size - ctx->start;
  180|      0|                    ctx->st.size = ctx->len;
  181|      0|                    ctx->st.valid |= ZIP_STAT_SIZE;
  ------------------
  |  |  324|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  182|      0|                }
  183|       |
  184|       |                /* when using a partial file, don't allow writing */
  185|      0|                if (ctx->fname && start == 0 && ops->write != NULL) {
  ------------------
  |  Branch (185:21): [True: 0, False: 0]
  |  Branch (185:35): [True: 0, False: 0]
  |  Branch (185:49): [True: 0, False: 0]
  ------------------
  186|      0|                    ctx->supports = ZIP_SOURCE_SUPPORTS_WRITABLE;
  ------------------
  |  |  293|      0|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  288|      0|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  281|      0|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  282|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  289|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  290|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  294|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  295|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  187|      0|                }
  188|      0|            }
  189|      0|        }
  190|       |
  191|      0|        ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_GET_FILE_ATTRIBUTES);
  ------------------
  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  192|      0|    }
  193|       |
  194|    490|    ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ACCEPT_EMPTY);
  ------------------
  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  195|    490|    if (ops->create_temp_output_cloning != NULL) {
  ------------------
  |  Branch (195:9): [True: 490, False: 0]
  ------------------
  196|    490|        if (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE)) {
  ------------------
  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (196:13): [True: 490, False: 0]
  ------------------
  197|    490|            ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING);
  ------------------
  |  |  275|    490|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  198|    490|        }
  199|    490|    }
  200|       |
  201|    490|    if ((zs = zip_source_function_create(read_file, ctx, error)) == NULL) {
  ------------------
  |  Branch (201:9): [True: 0, False: 490]
  ------------------
  202|      0|        free(ctx->fname);
  203|      0|        free(ctx);
  204|      0|        return NULL;
  205|      0|    }
  206|       |
  207|    490|    return zs;
  208|    490|}
zip_source_file_common.c:zip_source_file_stat_init:
   44|    490|static void zip_source_file_stat_init(zip_source_file_stat_t *st) {
   45|    490|    st->size = 0;
   46|    490|    st->mtime = time(NULL);
   47|    490|    st->exists = false;
   48|       |    st->regular_file = false;
   49|    490|}
zip_source_file_common.c:read_file:
  211|  22.5k|static zip_int64_t read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  212|  22.5k|    zip_source_file_context_t *ctx;
  213|  22.5k|    char *buf;
  214|       |
  215|  22.5k|    ctx = (zip_source_file_context_t *)state;
  216|  22.5k|    buf = (char *)data;
  217|       |
  218|  22.5k|    switch (cmd) {
  219|      0|    case ZIP_SOURCE_ACCEPT_EMPTY:
  ------------------
  |  Branch (219:5): [True: 0, False: 22.5k]
  ------------------
  220|      0|        return 0;
  221|       |
  222|    490|    case ZIP_SOURCE_BEGIN_WRITE:
  ------------------
  |  Branch (222:5): [True: 490, False: 22.0k]
  ------------------
  223|       |        /* write support should not be set if fname is NULL */
  224|    490|        if (ctx->fname == NULL) {
  ------------------
  |  Branch (224:13): [True: 0, False: 490]
  ------------------
  225|      0|            zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  226|      0|            return -1;
  227|      0|        }
  228|    490|        return ctx->ops->create_temp_output(ctx);
  229|       |
  230|      0|    case ZIP_SOURCE_BEGIN_WRITE_CLONING:
  ------------------
  |  Branch (230:5): [True: 0, False: 22.5k]
  ------------------
  231|       |        /* write support should not be set if fname is NULL */
  232|      0|        if (ctx->fname == NULL) {
  ------------------
  |  Branch (232:13): [True: 0, False: 0]
  ------------------
  233|      0|            zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  234|      0|            return -1;
  235|      0|        }
  236|      0|        return ctx->ops->create_temp_output_cloning(ctx, len);
  237|       |
  238|      0|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (238:5): [True: 0, False: 22.5k]
  ------------------
  239|      0|        if (ctx->fname) {
  ------------------
  |  Branch (239:13): [True: 0, False: 0]
  ------------------
  240|      0|            ctx->ops->close(ctx);
  241|      0|            ctx->f = NULL;
  242|      0|        }
  243|      0|        return 0;
  244|       |
  245|    490|    case ZIP_SOURCE_COMMIT_WRITE: {
  ------------------
  |  Branch (245:5): [True: 490, False: 22.0k]
  ------------------
  246|    490|        zip_int64_t ret = ctx->ops->commit_write(ctx);
  247|    490|        ctx->fout = NULL;
  248|    490|        if (ret == 0) {
  ------------------
  |  Branch (248:13): [True: 490, False: 0]
  ------------------
  249|    490|            free(ctx->tmpname);
  250|    490|            ctx->tmpname = NULL;
  251|    490|        }
  252|    490|        return ret;
  253|      0|    }
  254|       |
  255|    490|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (255:5): [True: 490, False: 22.0k]
  ------------------
  256|    490|        return zip_error_to_data(&ctx->error, data, len);
  257|       |
  258|    490|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (258:5): [True: 490, False: 22.0k]
  ------------------
  259|    490|        free(ctx->fname);
  260|    490|        free(ctx->tmpname);
  261|    490|        if (ctx->f) {
  ------------------
  |  Branch (261:13): [True: 0, False: 490]
  ------------------
  262|      0|            ctx->ops->close(ctx);
  263|      0|        }
  264|    490|        free(ctx);
  265|    490|        return 0;
  266|       |
  267|      0|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES:
  ------------------
  |  Branch (267:5): [True: 0, False: 22.5k]
  ------------------
  268|      0|        if (len < sizeof(ctx->attributes)) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  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|      0|        (void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
  ------------------
  |  |  200|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  273|      0|        return sizeof(ctx->attributes);
  274|       |
  275|      0|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (275:5): [True: 0, False: 22.5k]
  ------------------
  276|      0|        if (ctx->fname) {
  ------------------
  |  Branch (276:13): [True: 0, False: 0]
  ------------------
  277|      0|            if (ctx->ops->open(ctx) == false) {
  ------------------
  |  Branch (277:17): [True: 0, False: 0]
  ------------------
  278|      0|                return -1;
  279|      0|            }
  280|      0|        }
  281|       |
  282|      0|        if (ctx->start > 0) { /* TODO: rewind on re-open */
  ------------------
  |  Branch (282:13): [True: 0, False: 0]
  ------------------
  283|      0|            if (ctx->ops->seek(ctx, ctx->f, (zip_int64_t)ctx->start, SEEK_SET) == false) {
  ------------------
  |  Branch (283:17): [True: 0, False: 0]
  ------------------
  284|       |                /* TODO: skip by reading */
  285|      0|                return -1;
  286|      0|            }
  287|      0|        }
  288|      0|        ctx->offset = 0;
  289|      0|        return 0;
  290|       |
  291|      0|    case ZIP_SOURCE_READ: {
  ------------------
  |  Branch (291:5): [True: 0, False: 22.5k]
  ------------------
  292|      0|        zip_int64_t i;
  293|      0|        zip_uint64_t n;
  294|       |
  295|      0|        if (ctx->len > 0) {
  ------------------
  |  Branch (295:13): [True: 0, False: 0]
  ------------------
  296|      0|            n = ZIP_MIN(ctx->len - ctx->offset, len);
  ------------------
  |  |  503|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (503:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  297|      0|        }
  298|      0|        else {
  299|      0|            n = len;
  300|      0|        }
  301|       |
  302|      0|        if ((i = ctx->ops->read(ctx, buf, n)) < 0) {
  ------------------
  |  Branch (302:13): [True: 0, False: 0]
  ------------------
  303|      0|            zip_error_set(&ctx->error, ZIP_ER_READ, errno);
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  304|      0|            return -1;
  305|      0|        }
  306|      0|        ctx->offset += (zip_uint64_t)i;
  307|       |
  308|      0|        return i;
  309|      0|    }
  310|       |
  311|      0|    case ZIP_SOURCE_REMOVE:
  ------------------
  |  Branch (311:5): [True: 0, False: 22.5k]
  ------------------
  312|      0|        return ctx->ops->remove(ctx);
  313|       |
  314|      0|    case ZIP_SOURCE_ROLLBACK_WRITE:
  ------------------
  |  Branch (314:5): [True: 0, False: 22.5k]
  ------------------
  315|      0|        ctx->ops->rollback_write(ctx);
  316|      0|        ctx->fout = NULL;
  317|      0|        free(ctx->tmpname);
  318|      0|        ctx->tmpname = NULL;
  319|      0|        return 0;
  320|       |
  321|      0|    case ZIP_SOURCE_SEEK: {
  ------------------
  |  Branch (321:5): [True: 0, False: 22.5k]
  ------------------
  322|      0|        zip_int64_t new_offset = zip_source_seek_compute_offset(ctx->offset, ctx->len, data, len, &ctx->error);
  323|       |
  324|      0|        if (new_offset < 0) {
  ------------------
  |  Branch (324:13): [True: 0, False: 0]
  ------------------
  325|      0|            return -1;
  326|      0|        }
  327|       |
  328|       |        /* The actual offset inside the file must be representable as zip_int64_t. */
  329|      0|        if (new_offset > ZIP_INT64_MAX - (zip_int64_t)ctx->start) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (329:13): [True: 0, False: 0]
  ------------------
  330|      0|            zip_error_set(&ctx->error, ZIP_ER_SEEK, EOVERFLOW);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  331|      0|            return -1;
  332|      0|        }
  333|       |
  334|      0|        ctx->offset = (zip_uint64_t)new_offset;
  335|       |
  336|      0|        if (ctx->ops->seek(ctx, ctx->f, (zip_int64_t)(ctx->offset + ctx->start), SEEK_SET) == false) {
  ------------------
  |  Branch (336:13): [True: 0, False: 0]
  ------------------
  337|      0|            return -1;
  338|      0|        }
  339|      0|        return 0;
  340|      0|    }
  341|       |
  342|    980|    case ZIP_SOURCE_SEEK_WRITE: {
  ------------------
  |  Branch (342:5): [True: 980, False: 21.5k]
  ------------------
  343|    980|        zip_source_args_seek_t *args;
  344|       |
  345|    980|        args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
  ------------------
  |  |  311|    980|#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 (311:54): [True: 0, False: 980]
  |  |  ------------------
  ------------------
  346|    980|        if (args == NULL) {
  ------------------
  |  Branch (346:13): [True: 0, False: 980]
  ------------------
  347|      0|            return -1;
  348|      0|        }
  349|       |
  350|    980|        if (ctx->ops->seek(ctx, ctx->fout, args->offset, args->whence) == false) {
  ------------------
  |  Branch (350:13): [True: 0, False: 980]
  ------------------
  351|      0|            return -1;
  352|      0|        }
  353|    980|        return 0;
  354|    980|    }
  355|       |
  356|    490|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (356:5): [True: 490, False: 22.0k]
  ------------------
  357|    490|        if (len < sizeof(ctx->st)) {
  ------------------
  |  Branch (357:13): [True: 0, False: 490]
  ------------------
  358|      0|            return -1;
  359|      0|        }
  360|       |
  361|    490|        if (zip_error_code_zip(&ctx->stat_error) != 0) {
  ------------------
  |  Branch (361:13): [True: 490, False: 0]
  ------------------
  362|    490|            zip_error_set(&ctx->error, zip_error_code_zip(&ctx->stat_error), zip_error_code_system(&ctx->stat_error));
  363|    490|            return -1;
  364|    490|        }
  365|       |
  366|      0|        (void)memcpy_s(data, sizeof(ctx->st), &ctx->st, sizeof(ctx->st));
  ------------------
  |  |  200|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  367|      0|        return sizeof(ctx->st);
  368|    490|    }
  369|       |
  370|    490|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (370:5): [True: 490, False: 22.0k]
  ------------------
  371|    490|        return ctx->supports;
  372|       |
  373|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (373:5): [True: 0, False: 22.5k]
  ------------------
  374|      0|        return (zip_int64_t)ctx->offset;
  375|       |
  376|  3.92k|    case ZIP_SOURCE_TELL_WRITE:
  ------------------
  |  Branch (376:5): [True: 3.92k, False: 18.5k]
  ------------------
  377|  3.92k|        return ctx->ops->tell(ctx, ctx->fout);
  378|       |
  379|  14.6k|    case ZIP_SOURCE_WRITE:
  ------------------
  |  Branch (379:5): [True: 14.6k, False: 7.84k]
  ------------------
  380|  14.6k|        return ctx->ops->write(ctx, data, len);
  381|       |
  382|      0|    default:
  ------------------
  |  Branch (382:5): [True: 0, False: 22.5k]
  ------------------
  383|      0|        zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
  384|      0|        return -1;
  385|  22.5k|    }
  386|  22.5k|}

_zip_stdio_op_seek:
  111|    980|bool _zip_stdio_op_seek(zip_source_file_context_t *ctx, void *f, zip_int64_t offset, int whence) {
  112|       |#if ZIP_FSEEK_MAX > ZIP_INT64_MAX
  113|       |    if (offset > ZIP_FSEEK_MAX || offset < ZIP_FSEEK_MIN) {
  114|       |        zip_error_set(&ctx->error, ZIP_ER_SEEK, EOVERFLOW);
  115|       |        return false;
  116|       |    }
  117|       |#endif
  118|       |
  119|    980|    if (zip_os_fseek((FILE *)f, (zip_off_t)offset, whence) < 0) {
  ------------------
  |  |  163|    980|#define zip_os_fseek fseeko
  ------------------
  |  Branch (119:9): [True: 0, False: 980]
  ------------------
  120|      0|        zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  121|      0|        return false;
  122|      0|    }
  123|    980|    return true;
  124|    980|}
_zip_stdio_op_stat:
  127|    490|bool _zip_stdio_op_stat(zip_source_file_context_t *ctx, zip_source_file_stat_t *st) {
  128|    490|    zip_os_stat_t sb;
  129|       |
  130|    490|    int ret;
  131|       |
  132|    490|    if (ctx->fname) {
  ------------------
  |  Branch (132:9): [True: 490, False: 0]
  ------------------
  133|    490|        ret = zip_os_stat(ctx->fname, &sb);
  ------------------
  |  |  142|    490|#define zip_os_stat stat
  ------------------
  134|    490|    }
  135|      0|    else {
  136|      0|        ret = zip_os_fstat(fileno((FILE *)ctx->f), &sb);
  ------------------
  |  |  141|      0|#define zip_os_fstat fstat
  ------------------
  137|      0|    }
  138|       |
  139|    490|    if (ret < 0) {
  ------------------
  |  Branch (139:9): [True: 490, False: 0]
  ------------------
  140|    490|        if (errno == ENOENT) {
  ------------------
  |  Branch (140:13): [True: 490, False: 0]
  ------------------
  141|    490|            st->exists = false;
  142|    490|            return true;
  143|    490|        }
  144|      0|        zip_error_set(&ctx->error, ZIP_ER_READ, errno);
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  145|      0|        return false;
  146|    490|    }
  147|       |
  148|      0|    st->size = (zip_uint64_t)sb.st_size;
  149|      0|    st->mtime = sb.st_mtime;
  150|       |
  151|      0|    st->regular_file = S_ISREG(sb.st_mode);
  152|      0|    st->exists = true;
  153|       |
  154|       |    /* We're using UNIX file API, even on Windows; thus, we supply external file attributes with Unix values. */
  155|       |    /* TODO: This could be improved on Windows by providing Windows-specific file attributes */
  156|      0|    ctx->attributes.valid = ZIP_FILE_ATTRIBUTES_HOST_SYSTEM | ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES;
  ------------------
  |  |  361|      0|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
                  ctx->attributes.valid = ZIP_FILE_ATTRIBUTES_HOST_SYSTEM | ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES;
  ------------------
  |  |  364|      0|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
  157|      0|    ctx->attributes.host_system = ZIP_OPSYS_UNIX;
  ------------------
  |  |  228|      0|#define ZIP_OPSYS_UNIX 0x03u
  ------------------
  158|      0|    ctx->attributes.external_file_attributes = (((zip_uint32_t)sb.st_mode) << 16) | ((sb.st_mode & S_IWUSR) ? 0 : 1);
  ------------------
  |  Branch (158:86): [True: 0, False: 0]
  ------------------
  159|       |
  160|       |    return true;
  161|    490|}
_zip_stdio_op_tell:
  164|  3.92k|zip_int64_t _zip_stdio_op_tell(zip_source_file_context_t *ctx, void *f) {
  165|  3.92k|    zip_off_t offset = zip_os_ftell((FILE *)f);
  ------------------
  |  |  164|  3.92k|#define zip_os_ftell ftello
  ------------------
  166|       |
  167|  3.92k|    if (offset < 0) {
  ------------------
  |  Branch (167:9): [True: 0, False: 3.92k]
  ------------------
  168|      0|        zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  169|      0|    }
  170|       |
  171|  3.92k|    return offset;
  172|  3.92k|}

zip_source_file_create:
  102|    490|ZIP_EXTERN zip_source_t *zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
  103|    490|    if (fname == NULL || length < ZIP_LENGTH_UNCHECKED) {
  ------------------
  |  |  127|    490|#define ZIP_LENGTH_UNCHECKED (-2) /* only supported by zip_source_file and its variants */
  ------------------
  |  Branch (103:9): [True: 0, False: 490]
  |  Branch (103:26): [True: 0, False: 490]
  ------------------
  104|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  105|      0|        return NULL;
  106|      0|    }
  107|       |
  108|    490|    return zip_source_file_common_new(fname, NULL, start, length, NULL, &ops_stdio_named, NULL, error);
  109|    490|}
zip_source_file_stdio_named.c:_zip_stdio_op_commit_write:
  112|    490|static zip_int64_t _zip_stdio_op_commit_write(zip_source_file_context_t *ctx) {
  113|    490|    if (fclose(ctx->fout) < 0) {
  ------------------
  |  Branch (113:9): [True: 0, False: 490]
  ------------------
  114|      0|        zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
  ------------------
  |  |  137|      0|#define ZIP_ER_WRITE 6            /* S Write error */
  ------------------
  115|      0|        return -1;
  116|      0|    }
  117|    490|    if (rename(ctx->tmpname, ctx->fname) < 0) {
  ------------------
  |  Branch (117:9): [True: 0, False: 490]
  ------------------
  118|      0|        zip_error_set(&ctx->error, ZIP_ER_RENAME, errno);
  ------------------
  |  |  133|      0|#define ZIP_ER_RENAME 2           /* S Renaming temporary file failed */
  ------------------
  119|      0|        return -1;
  120|      0|    }
  121|       |
  122|    490|    return 0;
  123|    490|}
zip_source_file_stdio_named.c:_zip_stdio_op_create_temp_output:
  126|    490|static zip_int64_t _zip_stdio_op_create_temp_output(zip_source_file_context_t *ctx) {
  127|    490|    int fd = create_temp_file(ctx, true);
  128|       |
  129|    490|    if (fd < 0) {
  ------------------
  |  Branch (129:9): [True: 0, False: 490]
  ------------------
  130|      0|        return -1;
  131|      0|    }
  132|       |
  133|    490|    if ((ctx->fout = fdopen(fd, "r+b")) == NULL) {
  ------------------
  |  Branch (133:9): [True: 0, False: 490]
  ------------------
  134|      0|        zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
  ------------------
  |  |  143|      0|#define ZIP_ER_TMPOPEN 12         /* S Failure to create temporary file */
  ------------------
  135|      0|        close(fd);
  136|      0|        (void)remove(ctx->tmpname);
  137|      0|        free(ctx->tmpname);
  138|      0|        ctx->tmpname = NULL;
  139|      0|        return -1;
  140|      0|    }
  141|       |
  142|    490|    return 0;
  143|    490|}
zip_source_file_stdio_named.c:create_temp_file:
  281|    490|static int create_temp_file(zip_source_file_context_t *ctx, bool create_file) {
  282|    490|    char *temp;
  283|    490|    int mode;
  284|    490|    zip_os_stat_t st;
  285|    490|    int fd = 0;
  286|    490|    char *start, *end;
  287|       |
  288|    490|    if (zip_os_stat(ctx->fname, &st) == 0) {
  ------------------
  |  |  142|    490|#define zip_os_stat stat
  ------------------
  |  Branch (288:9): [True: 0, False: 490]
  ------------------
  289|      0|        mode = st.st_mode;
  290|      0|    }
  291|    490|    else {
  292|    490|        mode = -1;
  293|    490|    }
  294|       |
  295|    490|    size_t temp_size = strlen(ctx->fname) + 13;
  296|    490|    if ((temp = (char *)malloc(temp_size)) == NULL) {
  ------------------
  |  Branch (296:9): [True: 0, False: 490]
  ------------------
  297|      0|        zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  298|      0|        return -1;
  299|      0|    }
  300|    490|    snprintf_s(temp, temp_size, "%s.XXXXXX.part", ctx->fname);
  ------------------
  |  |  207|    490|#define snprintf_s snprintf
  ------------------
  301|    490|    end = temp + strlen(temp) - 5;
  302|    490|    start = end - 6;
  303|       |
  304|    490|    for (;;) {
  305|    490|        zip_uint32_t value = zip_random_uint32();
  306|    490|        char *xs = start;
  307|       |
  308|  3.43k|        while (xs < end) {
  ------------------
  |  Branch (308:16): [True: 2.94k, False: 490]
  ------------------
  309|  2.94k|            char digit = value % 36;
  310|  2.94k|            if (digit < 10) {
  ------------------
  |  Branch (310:17): [True: 823, False: 2.11k]
  ------------------
  311|    823|                *(xs++) = digit + '0';
  312|    823|            }
  313|  2.11k|            else {
  314|  2.11k|                *(xs++) = digit - 10 + 'a';
  315|  2.11k|            }
  316|  2.94k|            value /= 36;
  317|  2.94k|        }
  318|       |
  319|    490|        if (create_file) {
  ------------------
  |  Branch (319:13): [True: 490, False: 0]
  ------------------
  320|    490|            if ((fd = open(temp, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, mode == -1 ? 0666 : (mode_t)mode)) >= 0) {
  ------------------
  |  Branch (320:17): [True: 490, False: 0]
  |  Branch (320:73): [True: 490, False: 0]
  ------------------
  321|    490|                if (mode != -1) {
  ------------------
  |  Branch (321:21): [True: 0, False: 490]
  ------------------
  322|       |                    /* open() honors umask(), which we don't want in this case */
  323|      0|#ifdef HAVE_FCHMOD
  324|      0|                    (void)fchmod(fd, (mode_t)mode);
  325|       |#else
  326|       |                    (void)chmod(temp, (mode_t)mode);
  327|       |#endif
  328|      0|                }
  329|    490|                break;
  330|    490|            }
  331|      0|            if (errno != EEXIST) {
  ------------------
  |  Branch (331:17): [True: 0, False: 0]
  ------------------
  332|      0|                zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
  ------------------
  |  |  143|      0|#define ZIP_ER_TMPOPEN 12         /* S Failure to create temporary file */
  ------------------
  333|      0|                free(temp);
  334|      0|                return -1;
  335|      0|            }
  336|      0|        }
  337|      0|        else {
  338|      0|            if (zip_os_stat(temp, &st) < 0) {
  ------------------
  |  |  142|      0|#define zip_os_stat stat
  ------------------
  |  Branch (338:17): [True: 0, False: 0]
  ------------------
  339|      0|                if (errno == ENOENT) {
  ------------------
  |  Branch (339:21): [True: 0, False: 0]
  ------------------
  340|      0|                    break;
  341|      0|                }
  342|      0|                else {
  343|      0|                    zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
  ------------------
  |  |  143|      0|#define ZIP_ER_TMPOPEN 12         /* S Failure to create temporary file */
  ------------------
  344|      0|                    free(temp);
  345|      0|                    return -1;
  346|      0|                }
  347|      0|            }
  348|      0|        }
  349|    490|    }
  350|       |
  351|    490|    ctx->tmpname = temp;
  352|       |
  353|    490|    return fd; /* initialized to 0 if !create_file */
  354|    490|}
zip_source_file_stdio_named.c:_zip_stdio_op_strdup:
  262|    490|static char *_zip_stdio_op_strdup(zip_source_file_context_t *ctx, const char *string) {
  263|    490|    return strdup(string);
  264|    490|}
zip_source_file_stdio_named.c:_zip_stdio_op_write:
  267|  14.6k|static zip_int64_t _zip_stdio_op_write(zip_source_file_context_t *ctx, const void *data, zip_uint64_t len) {
  268|  14.6k|    size_t ret;
  269|       |
  270|  14.6k|    clearerr((FILE *)ctx->fout);
  271|  14.6k|    ret = fwrite(data, 1, len, (FILE *)ctx->fout);
  272|  14.6k|    if (ret != len || ferror((FILE *)ctx->fout)) {
  ------------------
  |  Branch (272:9): [True: 0, False: 14.6k]
  |  Branch (272:23): [True: 0, False: 14.6k]
  ------------------
  273|      0|        zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
  ------------------
  |  |  137|      0|#define ZIP_ER_WRITE 6            /* S Write error */
  ------------------
  274|      0|        return -1;
  275|      0|    }
  276|       |
  277|  14.6k|    return (zip_int64_t)ret;
  278|  14.6k|}

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

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

zip_source_get_dos_time:
   38|    980|int zip_source_get_dos_time(zip_source_t *src, zip_dostime_t *dos_time) {
   39|    980|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 980]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|    980|    if (dos_time == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 980]
  ------------------
   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|    980|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (47:9): [True: 0, False: 980]
  ------------------
   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|    980|    if (zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_GET_DOS_TIME)) {
  ------------------
  |  |  275|    980|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (51:9): [True: 0, False: 980]
  ------------------
   52|      0|        zip_int64_t n = _zip_source_call(src, dos_time, sizeof(*dos_time), ZIP_SOURCE_GET_DOS_TIME);
   53|       |
   54|      0|        if (n < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 0]
  ------------------
   55|      0|            return -1;
   56|      0|        }
   57|      0|        else if (n == 0) {
  ------------------
  |  Branch (57:18): [True: 0, False: 0]
  ------------------
   58|      0|            return 0;
   59|      0|        }
   60|      0|        else if (n == sizeof(*dos_time)) {
  ------------------
  |  Branch (60:18): [True: 0, False: 0]
  ------------------
   61|      0|            return 1;
   62|      0|        }
   63|      0|        else {
   64|      0|            zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   65|      0|            return -1;
   66|      0|        }
   67|      0|    }
   68|    980|    else {
   69|    980|        return 0;
   70|    980|    }
   71|    980|}

zip_file_attributes_init:
   36|  9.31k|ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *attributes) {
   37|  9.31k|    attributes->valid = 0;
   38|  9.31k|    attributes->version = 1;
   39|  9.31k|}
zip_source_get_file_attributes:
   41|  4.90k|int zip_source_get_file_attributes(zip_source_t *src, zip_file_attributes_t *attributes) {
   42|  4.90k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 4.90k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|  4.90k|    if (attributes == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 4.90k]
  ------------------
   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|  4.90k|    zip_file_attributes_init(attributes);
   51|       |
   52|  4.90k|    if (src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_GET_FILE_ATTRIBUTES)) {
  ------------------
  |  |  275|  4.90k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (52:9): [True: 3.43k, False: 1.47k]
  ------------------
   53|  3.43k|        if (_zip_source_call(src, attributes, sizeof(*attributes), ZIP_SOURCE_GET_FILE_ATTRIBUTES) < 0) {
  ------------------
  |  Branch (53:13): [True: 0, False: 3.43k]
  ------------------
   54|      0|            return -1;
   55|      0|        }
   56|  3.43k|    }
   57|       |
   58|  4.90k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|  4.90k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 3.43k, False: 1.47k]
  |  |  ------------------
  ------------------
   59|  3.43k|        zip_file_attributes_t lower_attributes;
   60|       |
   61|  3.43k|        zip_file_attributes_init(&lower_attributes);
   62|       |
   63|  3.43k|        if (zip_source_get_file_attributes(src->src, &lower_attributes) < 0) {
  ------------------
  |  Branch (63:13): [True: 0, False: 3.43k]
  ------------------
   64|      0|            zip_error_set_from_source(&src->error, src->src);
   65|      0|            return -1;
   66|      0|        }
   67|       |
   68|  3.43k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) == 0) {
  ------------------
  |  |  361|  3.43k|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
                      if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) == 0) {
  ------------------
  |  |  361|      0|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
  |  Branch (68:13): [True: 0, False: 3.43k]
  |  Branch (68:75): [True: 0, False: 0]
  ------------------
   69|      0|            attributes->host_system = lower_attributes.host_system;
   70|      0|            attributes->valid |= ZIP_FILE_ATTRIBUTES_HOST_SYSTEM;
  ------------------
  |  |  361|      0|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
   71|      0|        }
   72|  3.43k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_ASCII) && (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) == 0) {
  ------------------
  |  |  362|  3.43k|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
                      if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_ASCII) && (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) == 0) {
  ------------------
  |  |  362|      0|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
  |  Branch (72:13): [True: 0, False: 3.43k]
  |  Branch (72:69): [True: 0, False: 0]
  ------------------
   73|      0|            attributes->ascii = lower_attributes.ascii;
   74|      0|            attributes->valid |= ZIP_FILE_ATTRIBUTES_ASCII;
  ------------------
  |  |  362|      0|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
   75|      0|        }
   76|  3.43k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED)) {
  ------------------
  |  |  363|  3.43k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  |  Branch (76:13): [True: 980, False: 2.45k]
  ------------------
   77|    980|            if (attributes->valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED) {
  ------------------
  |  |  363|    980|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  |  Branch (77:17): [True: 980, False: 0]
  ------------------
   78|    980|                attributes->version_needed = ZIP_MAX(lower_attributes.version_needed, attributes->version_needed);
  ------------------
  |  |  502|    980|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (502:24): [True: 0, False: 980]
  |  |  ------------------
  ------------------
   79|    980|            }
   80|      0|            else {
   81|      0|                attributes->version_needed = lower_attributes.version_needed;
   82|      0|                attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED;
  ------------------
  |  |  363|      0|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
   83|      0|            }
   84|    980|        }
   85|  3.43k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) == 0) {
  ------------------
  |  |  364|  3.43k|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
                      if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) == 0) {
  ------------------
  |  |  364|      0|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
  |  Branch (85:13): [True: 0, False: 3.43k]
  |  Branch (85:88): [True: 0, False: 0]
  ------------------
   86|      0|            attributes->external_file_attributes = lower_attributes.external_file_attributes;
   87|      0|            attributes->valid |= ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES;
  ------------------
  |  |  364|      0|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
   88|      0|        }
   89|  3.43k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS)) {
  ------------------
  |  |  365|  3.43k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  |  Branch (89:13): [True: 980, False: 2.45k]
  ------------------
   90|    980|            if (attributes->valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS) {
  ------------------
  |  |  365|    980|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  |  Branch (90:17): [True: 980, False: 0]
  ------------------
   91|       |                /* only take from lower level what is not defined at current level */
   92|    980|                lower_attributes.general_purpose_bit_mask &= ~attributes->general_purpose_bit_mask;
   93|       |
   94|    980|                attributes->general_purpose_bit_flags |= lower_attributes.general_purpose_bit_flags & lower_attributes.general_purpose_bit_mask;
   95|    980|                attributes->general_purpose_bit_mask |= lower_attributes.general_purpose_bit_mask;
   96|    980|            }
   97|      0|            else {
   98|      0|                attributes->valid |= ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  365|      0|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
   99|      0|                attributes->general_purpose_bit_flags = lower_attributes.general_purpose_bit_flags;
  100|      0|                attributes->general_purpose_bit_mask = lower_attributes.general_purpose_bit_mask;
  101|      0|            }
  102|    980|        }
  103|  3.43k|    }
  104|       |
  105|  4.90k|    return 0;
  106|  4.90k|}

zip_source_layered:
   40|    980|zip_source_t *zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud) {
   41|    980|    if (za == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 980]
  ------------------
   42|      0|        return NULL;
   43|      0|    }
   44|       |
   45|    980|    return zip_source_layered_create(src, cb, ud, &za->error);
   46|    980|}
zip_source_layered_create:
   49|  1.47k|zip_source_t *zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error) {
   50|  1.47k|    zip_source_t *zs;
   51|  1.47k|    zip_int64_t lower_supports, supports;
   52|       |
   53|  1.47k|    lower_supports = zip_source_supports(src);
   54|  1.47k|    supports = cb(src, ud, &lower_supports, sizeof(lower_supports), ZIP_SOURCE_SUPPORTS);
   55|  1.47k|    if (supports < 0) {
  ------------------
  |  Branch (55:9): [True: 0, False: 1.47k]
  ------------------
   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|  1.47k|    if ((zs = _zip_source_new(error)) == NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 1.47k]
  ------------------
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|  1.47k|    zs->src = src;
   66|  1.47k|    zs->cb.l = cb;
   67|  1.47k|    zs->ud = ud;
   68|  1.47k|    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|  1.47k|    zs->supports &= ~(ZIP_SOURCE_SUPPORTS_WRITABLE & ~ZIP_SOURCE_SUPPORTS_SEEKABLE);
  ------------------
  |  |  293|  1.47k|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  288|  1.47k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  281|  1.47k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  282|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  289|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  290|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  294|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  295|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  zs->supports &= ~(ZIP_SOURCE_SUPPORTS_WRITABLE & ~ZIP_SOURCE_SUPPORTS_SEEKABLE);
  ------------------
  |  |  288|  1.47k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  281|  1.47k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  282|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  289|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  290|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  1.47k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  275|  1.47k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
   72|       |
   73|  1.47k|    return zs;
   74|  1.47k|}

zip_source_open:
   37|  1.96k|ZIP_EXTERN int zip_source_open(zip_source_t *src) {
   38|  1.96k|    if (src->source_closed) {
  ------------------
  |  Branch (38:9): [True: 0, False: 1.96k]
  ------------------
   39|      0|        return -1;
   40|      0|    }
   41|  1.96k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (41:9): [True: 0, False: 1.96k]
  ------------------
   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|  1.96k|    if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  432|  1.96k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (432:41): [True: 0, False: 1.96k]
  |  |  ------------------
  ------------------
   47|      0|        if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) == 0) {
  ------------------
  |  |  275|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (47:13): [True: 0, False: 0]
  ------------------
   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|      0|    }
   52|  1.96k|    else {
   53|  1.96k|        if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|  1.96k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 1.47k, False: 490]
  |  |  ------------------
  ------------------
   54|  1.47k|            if (zip_source_open(src->src) < 0) {
  ------------------
  |  Branch (54:17): [True: 0, False: 1.47k]
  ------------------
   55|      0|                zip_error_set_from_source(&src->error, src->src);
   56|      0|                return -1;
   57|      0|            }
   58|  1.47k|        }
   59|       |
   60|  1.96k|        if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_OPEN) < 0) {
  ------------------
  |  Branch (60:13): [True: 0, False: 1.96k]
  ------------------
   61|      0|            if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|      0|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   62|      0|                zip_source_close(src->src);
   63|      0|            }
   64|      0|            return -1;
   65|      0|        }
   66|  1.96k|    }
   67|       |
   68|  1.96k|    src->eof = false;
   69|  1.96k|    src->had_read_error = false;
   70|  1.96k|    _zip_error_clear(&src->error);
   71|  1.96k|    src->bytes_read = 0;
   72|  1.96k|    src->open_count++;
   73|       |
   74|  1.96k|    return 0;
   75|  1.96k|}

zip_source_pkware_encode:
   55|    490|zip_source_t *zip_source_pkware_encode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password) {
   56|    490|    struct trad_pkware *ctx;
   57|    490|    zip_source_t *s2;
   58|       |
   59|    490|    if (password == NULL || src == NULL || em != ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|    490|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (59:9): [True: 0, False: 490]
  |  Branch (59:29): [True: 0, False: 490]
  |  Branch (59:44): [True: 0, False: 490]
  ------------------
   60|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   61|      0|        return NULL;
   62|      0|    }
   63|    490|    if (!(flags & ZIP_CODEC_ENCODE)) {
  ------------------
  |  |  115|    490|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (63:9): [True: 0, False: 490]
  ------------------
   64|      0|        zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
   65|      0|        return NULL;
   66|      0|    }
   67|       |
   68|    490|    if ((ctx = trad_pkware_new(password, &za->error)) == NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 490]
  ------------------
   69|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   70|      0|        return NULL;
   71|      0|    }
   72|       |
   73|    490|    if (zip_source_get_dos_time(src, &ctx->dostime) <= 0) {
  ------------------
  |  Branch (73:9): [True: 490, False: 0]
  ------------------
   74|    490|        zip_stat_t st;
   75|       |
   76|    490|        if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (76:13): [True: 0, False: 490]
  ------------------
   77|      0|            zip_error_set_from_source(&za->error, src);
   78|      0|            trad_pkware_free(ctx);
   79|      0|            return NULL;
   80|      0|        }
   81|    490|        if (_zip_u2d_time((st.valid & ZIP_STAT_MTIME) ? st.mtime : time(NULL), &ctx->dostime, &za->error) < 0) {
  ------------------
  |  |  326|    490|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (81:13): [True: 0, False: 490]
  |  Branch (81:27): [True: 490, False: 0]
  ------------------
   82|      0|            trad_pkware_free(ctx);
   83|      0|            return NULL;
   84|      0|        }
   85|    490|    }
   86|       |
   87|    490|    if ((s2 = zip_source_layered(za, src, pkware_encrypt, ctx)) == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 490]
  ------------------
   88|      0|        trad_pkware_free(ctx);
   89|      0|        return NULL;
   90|      0|    }
   91|       |
   92|    490|    return s2;
   93|    490|}
zip_source_pkware_encode.c:pkware_encrypt:
  122|  14.6k|static zip_int64_t pkware_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip_source_cmd_t cmd) {
  123|  14.6k|    struct trad_pkware *ctx;
  124|  14.6k|    zip_int64_t n;
  125|  14.6k|    zip_uint64_t buffer_n;
  126|       |
  127|  14.6k|    ctx = (struct trad_pkware *)ud;
  128|       |
  129|  14.6k|    switch (cmd) {
  130|    490|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (130:5): [True: 490, False: 14.1k]
  ------------------
  131|    490|        ctx->eof = false;
  132|       |
  133|       |        /* initialize keys */
  134|    490|        _zip_pkware_keys_reset(&ctx->keys);
  135|    490|        _zip_pkware_encrypt(&ctx->keys, NULL, (const zip_uint8_t *)ctx->password, strlen(ctx->password));
  136|       |
  137|    490|        if (encrypt_header(src, ctx) < 0) {
  ------------------
  |  Branch (137:13): [True: 0, False: 490]
  ------------------
  138|      0|            return -1;
  139|      0|        }
  140|    490|        return 0;
  141|       |
  142|  11.2k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (142:5): [True: 11.2k, False: 3.43k]
  ------------------
  143|  11.2k|        buffer_n = 0;
  144|       |
  145|  11.2k|        if (ctx->buffer) {
  ------------------
  |  Branch (145:13): [True: 490, False: 10.7k]
  ------------------
  146|       |            /* write header values to data */
  147|    490|            buffer_n = _zip_buffer_read(ctx->buffer, data, length);
  148|    490|            data = (zip_uint8_t *)data + buffer_n;
  149|    490|            length -= buffer_n;
  150|       |
  151|    490|            if (_zip_buffer_eof(ctx->buffer)) {
  ------------------
  |  Branch (151:17): [True: 490, False: 0]
  ------------------
  152|    490|                _zip_buffer_free(ctx->buffer);
  153|    490|                ctx->buffer = NULL;
  154|    490|            }
  155|    490|        }
  156|       |
  157|  11.2k|        if (ctx->eof) {
  ------------------
  |  Branch (157:13): [True: 469, False: 10.7k]
  ------------------
  158|    469|            return (zip_int64_t)buffer_n;
  159|    469|        }
  160|       |
  161|  10.7k|        if ((n = zip_source_read(src, data, length)) < 0) {
  ------------------
  |  Branch (161:13): [True: 0, False: 10.7k]
  ------------------
  162|      0|            zip_error_set_from_source(&ctx->error, src);
  163|      0|            return -1;
  164|      0|        }
  165|       |
  166|  10.7k|        _zip_pkware_encrypt(&ctx->keys, (zip_uint8_t *)data, (zip_uint8_t *)data, (zip_uint64_t)n);
  167|       |
  168|  10.7k|        if ((zip_uint64_t)n < length) {
  ------------------
  |  Branch (168:13): [True: 490, False: 10.2k]
  ------------------
  169|    490|            ctx->eof = true;
  170|    490|        }
  171|       |
  172|  10.7k|        return (zip_int64_t)buffer_n + n;
  173|       |
  174|    490|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (174:5): [True: 490, False: 14.1k]
  ------------------
  175|    490|        _zip_buffer_free(ctx->buffer);
  176|    490|        ctx->buffer = NULL;
  177|    490|        return 0;
  178|       |
  179|    490|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (179:5): [True: 490, False: 14.1k]
  ------------------
  180|    490|        zip_stat_t *st;
  181|       |
  182|    490|        st = (zip_stat_t *)data;
  183|    490|        st->encryption_method = ZIP_EM_TRAD_PKWARE;
  ------------------
  |  |  208|    490|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  184|    490|        st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|    490|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  185|    490|        if (st->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  325|    490|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (185:13): [True: 490, False: 0]
  ------------------
  186|    490|            st->comp_size += ZIP_CRYPTO_PKWARE_HEADERLEN;
  ------------------
  |  |   77|    490|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  187|    490|        }
  188|       |
  189|    490|        return 0;
  190|  10.7k|    }
  191|       |
  192|    980|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (192:5): [True: 980, False: 13.6k]
  ------------------
  193|    980|        zip_file_attributes_t *attributes = (zip_file_attributes_t *)data;
  194|    980|        if (length < sizeof(*attributes)) {
  ------------------
  |  Branch (194:13): [True: 0, False: 980]
  ------------------
  195|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  196|      0|            return -1;
  197|      0|        }
  198|    980|        attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  363|    980|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
                      attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  365|    980|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  199|    980|        attributes->version_needed = 20;
  200|    980|        attributes->general_purpose_bit_flags = ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  252|    980|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  201|    980|        attributes->general_purpose_bit_mask = ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  252|    980|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  202|       |
  203|    980|        return 0;
  204|    980|    }
  205|       |
  206|      0|    case ZIP_SOURCE_GET_DOS_TIME:
  ------------------
  |  Branch (206:5): [True: 0, False: 14.6k]
  ------------------
  207|      0|        if (length < sizeof(ctx->dostime)) {
  ------------------
  |  Branch (207:13): [True: 0, False: 0]
  ------------------
  208|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  209|      0|            return -1;
  210|      0|        }
  211|      0|        (void)memcpy_s(data, sizeof(ctx->dostime), &ctx->dostime, sizeof(ctx->dostime));
  ------------------
  |  |  200|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  212|      0|        return sizeof(ctx->dostime);
  213|       |
  214|    490|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (214:5): [True: 490, False: 14.1k]
  ------------------
  215|    490|        return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_GET_DOS_TIME, -1);
  216|       |
  217|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (217:5): [True: 0, False: 14.6k]
  ------------------
  218|      0|        return zip_error_to_data(&ctx->error, data, length);
  219|       |
  220|    490|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (220:5): [True: 490, False: 14.1k]
  ------------------
  221|    490|        trad_pkware_free(ctx);
  222|    490|        return 0;
  223|       |
  224|      0|    default:
  ------------------
  |  Branch (224:5): [True: 0, False: 14.6k]
  ------------------
  225|      0|        return zip_source_pass_to_lower_layer(src, data, length, cmd);
  226|  14.6k|    }
  227|  14.6k|}
zip_source_pkware_encode.c:encrypt_header:
   96|    490|static int encrypt_header(zip_source_t *src, struct trad_pkware *ctx) {
   97|    490|    zip_uint8_t *header;
   98|       |
   99|    490|    if ((ctx->buffer = _zip_buffer_new(NULL, ZIP_CRYPTO_PKWARE_HEADERLEN)) == NULL) {
  ------------------
  |  |   77|    490|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (99:9): [True: 0, False: 490]
  ------------------
  100|      0|        zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  101|      0|        return -1;
  102|      0|    }
  103|       |
  104|    490|    header = _zip_buffer_data(ctx->buffer);
  105|       |
  106|       |    /* generate header from random bytes and mtime
  107|       |       see appnote.iz, XIII. Decryption, Step 2, last paragraph */
  108|    490|    if (!zip_secure_random(header, ZIP_CRYPTO_PKWARE_HEADERLEN - 1)) {
  ------------------
  |  |   77|    490|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (108:9): [True: 0, False: 490]
  ------------------
  109|      0|        zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  110|      0|        _zip_buffer_free(ctx->buffer);
  111|      0|        ctx->buffer = NULL;
  112|      0|        return -1;
  113|      0|    }
  114|    490|    header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] = (zip_uint8_t)((ctx->dostime.time >> 8) & 0xff);
  ------------------
  |  |   77|    490|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  115|       |
  116|    490|    _zip_pkware_encrypt(&ctx->keys, header, header, ZIP_CRYPTO_PKWARE_HEADERLEN);
  ------------------
  |  |   77|    490|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  117|       |
  118|    490|    return 0;
  119|    490|}
zip_source_pkware_encode.c:trad_pkware_new:
  230|    490|static struct trad_pkware *trad_pkware_new(const char *password, zip_error_t *error) {
  231|    490|    struct trad_pkware *ctx;
  232|       |
  233|    490|    if ((ctx = (struct trad_pkware *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (233:9): [True: 0, False: 490]
  ------------------
  234|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  235|      0|        return NULL;
  236|      0|    }
  237|       |
  238|    490|    if ((ctx->password = strdup(password)) == NULL) {
  ------------------
  |  Branch (238:9): [True: 0, False: 490]
  ------------------
  239|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  240|      0|        free(ctx);
  241|      0|        return NULL;
  242|      0|    }
  243|    490|    ctx->buffer = NULL;
  244|    490|    zip_error_init(&ctx->error);
  245|       |
  246|    490|    return ctx;
  247|    490|}
zip_source_pkware_encode.c:trad_pkware_free:
  250|    490|static void trad_pkware_free(struct trad_pkware *ctx) {
  251|    490|    if (ctx == NULL) {
  ------------------
  |  Branch (251:9): [True: 0, False: 490]
  ------------------
  252|      0|        return;
  253|      0|    }
  254|       |
  255|    490|    free(ctx->password);
  256|    490|    _zip_buffer_free(ctx->buffer);
  257|    490|    zip_error_fini(&ctx->error);
  258|    490|    free(ctx);
  259|    490|}

zip_source_read:
   38|  48.6k|zip_int64_t zip_source_read(zip_source_t *src, void *data, zip_uint64_t len) {
   39|  48.6k|    zip_uint64_t bytes_read;
   40|  48.6k|    zip_int64_t n;
   41|       |
   42|  48.6k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 48.6k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|  48.6k|    if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
  ------------------
  |  |  432|  97.3k|#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|  97.3k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (45:9): [True: 0, False: 48.6k]
  |  Branch (45:45): [True: 0, False: 48.6k]
  |  Branch (45:69): [True: 48.6k, False: 0]
  |  Branch (45:80): [True: 0, False: 48.6k]
  ------------------
   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|  48.6k|    if (src->had_read_error) {
  ------------------
  |  Branch (50:9): [True: 0, False: 48.6k]
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|  48.6k|    if (_zip_source_eof(src)) {
  ------------------
  |  Branch (54:9): [True: 1.35k, False: 47.3k]
  ------------------
   55|  1.35k|        return 0;
   56|  1.35k|    }
   57|       |
   58|  47.3k|    if (len == 0) {
  ------------------
  |  Branch (58:9): [True: 0, False: 47.3k]
  ------------------
   59|      0|        return 0;
   60|      0|    }
   61|       |
   62|  47.3k|    bytes_read = 0;
   63|  94.5k|    while (bytes_read < len) {
  ------------------
  |  Branch (63:12): [True: 49.1k, False: 45.3k]
  ------------------
   64|  49.1k|        if ((n = _zip_source_call(src, (zip_uint8_t *)data + bytes_read, len - bytes_read, ZIP_SOURCE_READ)) < 0) {
  ------------------
  |  Branch (64:13): [True: 0, False: 49.1k]
  ------------------
   65|      0|            src->had_read_error = true;
   66|      0|            if (bytes_read == 0) {
  ------------------
  |  Branch (66:17): [True: 0, False: 0]
  ------------------
   67|      0|                return -1;
   68|      0|            }
   69|      0|            else {
   70|      0|                return (zip_int64_t)bytes_read;
   71|      0|            }
   72|      0|        }
   73|       |
   74|  49.1k|        if (n == 0) {
  ------------------
  |  Branch (74:13): [True: 1.96k, False: 47.1k]
  ------------------
   75|  1.96k|            src->eof = 1;
   76|  1.96k|            break;
   77|  1.96k|        }
   78|       |
   79|  47.1k|        bytes_read += (zip_uint64_t)n;
   80|  47.1k|    }
   81|       |
   82|  47.3k|    if (src->bytes_read + bytes_read < src->bytes_read) {
  ------------------
  |  Branch (82:9): [True: 0, False: 47.3k]
  ------------------
   83|      0|        src->bytes_read = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   84|      0|    }
   85|  47.3k|    else {
   86|  47.3k|        src->bytes_read += bytes_read;
   87|  47.3k|    }
   88|  47.3k|    return (zip_int64_t)bytes_read;
   89|  47.3k|}
_zip_source_eof:
   92|  48.6k|bool _zip_source_eof(zip_source_t *src) {
   93|  48.6k|    return src->eof;
   94|  48.6k|}

zip_source_seek_write:
   38|    980|ZIP_EXTERN int zip_source_seek_write(zip_source_t *src, zip_int64_t offset, int whence) {
   39|    980|    zip_source_args_seek_t args;
   40|       |
   41|    980|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|    980|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 0, False: 980]
  |  |  ------------------
  ------------------
   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|    980|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
  ------------------
  |  |  433|  1.96k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
  |  Branch (46:9): [True: 0, False: 980]
  |  Branch (46:46): [True: 0, False: 980]
  |  Branch (46:68): [True: 0, False: 0]
  |  Branch (46:90): [True: 0, False: 0]
  ------------------
   47|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|    980|    args.offset = offset;
   52|    980|    args.whence = whence;
   53|       |
   54|    980|    return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK_WRITE) < 0 ? -1 : 0);
  ------------------
  |  Branch (54:13): [True: 0, False: 980]
  ------------------
   55|    980|}

zip_source_stat:
   38|  5.39k|ZIP_EXTERN int zip_source_stat(zip_source_t *src, zip_stat_t *st) {
   39|  5.39k|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 5.39k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|  5.39k|    if (st == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 5.39k]
  ------------------
   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|  5.39k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (47:9): [True: 0, False: 5.39k]
  ------------------
   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|  5.39k|    zip_stat_init(st);
   52|       |
   53|  5.39k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|  5.39k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 2.94k, False: 2.45k]
  |  |  ------------------
  ------------------
   54|  2.94k|        if (zip_source_stat(src->src, st) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 2.94k]
  ------------------
   55|      0|            zip_error_set_from_source(&src->error, src->src);
   56|      0|            return -1;
   57|      0|        }
   58|  2.94k|    }
   59|       |
   60|  5.39k|    if (_zip_source_call(src, st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
  ------------------
  |  Branch (60:9): [True: 490, False: 4.90k]
  ------------------
   61|    490|        return -1;
   62|    490|    }
   63|       |
   64|  4.90k|    return 0;
   65|  5.39k|}

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

zip_source_tell_write:
   38|  3.92k|ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *src) {
   39|  3.92k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  434|  3.92k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (434:36): [True: 0, False: 3.92k]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|  3.92k|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  433|  3.92k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
  |  Branch (44:9): [True: 0, False: 3.92k]
  ------------------
   45|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|  3.92k|    return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL_WRITE);
   50|  3.92k|}

zip_source_write:
   38|  14.6k|ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *src, const void *data, zip_uint64_t length) {
   39|  14.6k|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) {
  ------------------
  |  |  433|  29.3k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
                  if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  14.6k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (39:9): [True: 0, False: 14.6k]
  |  Branch (39:45): [True: 0, False: 14.6k]
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|  14.6k|    return _zip_source_call(src, (void *)data, length, ZIP_SOURCE_WRITE);
   45|  14.6k|}

zip_stat_init:
   39|  8.33k|ZIP_EXTERN void zip_stat_init(zip_stat_t *st) {
   40|  8.33k|    st->valid = 0;
   41|  8.33k|    st->name = NULL;
   42|  8.33k|    st->index = ZIP_UINT64_MAX;
  ------------------
  |  |   46|  8.33k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   43|  8.33k|    st->crc = 0;
   44|  8.33k|    st->mtime = (time_t)-1;
   45|  8.33k|    st->size = 0;
   46|  8.33k|    st->comp_size = 0;
   47|  8.33k|    st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|  8.33k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
   48|  8.33k|    st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  8.33k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
   49|  8.33k|}

_zip_string_free:
   69|  2.45k|void _zip_string_free(zip_string_t *s) {
   70|  2.45k|    if (s == NULL) {
  ------------------
  |  Branch (70:9): [True: 980, False: 1.47k]
  ------------------
   71|    980|        return;
   72|    980|    }
   73|       |
   74|  1.47k|    free(s->raw);
   75|  1.47k|    free(s->converted);
   76|  1.47k|    free(s);
   77|  1.47k|}
_zip_string_get:
   80|  1.96k|const zip_uint8_t *_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error) {
   81|  1.96k|    static const zip_uint8_t empty[1] = "";
   82|       |
   83|  1.96k|    if (string == NULL) {
  ------------------
  |  Branch (83:9): [True: 0, False: 1.96k]
  ------------------
   84|      0|        if (lenp) {
  ------------------
  |  Branch (84:13): [True: 0, False: 0]
  ------------------
   85|      0|            *lenp = 0;
   86|      0|        }
   87|      0|        return empty;
   88|      0|    }
   89|       |
   90|  1.96k|    if ((flags & ZIP_FL_ENC_RAW) == 0) {
  ------------------
  |  |  102|  1.96k|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
  |  Branch (90:9): [True: 1.96k, False: 0]
  ------------------
   91|       |        /* start guessing */
   92|  1.96k|        if (string->encoding == ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (92:13): [True: 980, False: 980]
  ------------------
   93|       |            /* guess encoding, sets string->encoding */
   94|    980|            (void)_zip_guess_encoding(string, ZIP_ENCODING_UNKNOWN);
   95|    980|        }
   96|       |
   97|  1.96k|        if (((flags & ZIP_FL_ENC_STRICT) && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN) || (string->encoding == ZIP_ENCODING_CP437)) {
  ------------------
  |  |  103|  1.96k|#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
  ------------------
  |  Branch (97:14): [True: 0, False: 1.96k]
  |  Branch (97:45): [True: 0, False: 0]
  |  Branch (97:87): [True: 0, False: 0]
  |  Branch (97:135): [True: 0, False: 1.96k]
  ------------------
   98|      0|            if (string->converted == NULL) {
  ------------------
  |  Branch (98:17): [True: 0, False: 0]
  ------------------
   99|      0|                if ((string->converted = _zip_cp437_to_utf8(string->raw, string->length, &string->converted_length, error)) == NULL) {
  ------------------
  |  Branch (99:21): [True: 0, False: 0]
  ------------------
  100|      0|                    return NULL;
  101|      0|                }
  102|      0|            }
  103|      0|            if (lenp) {
  ------------------
  |  Branch (103:17): [True: 0, False: 0]
  ------------------
  104|      0|                *lenp = string->converted_length;
  105|      0|            }
  106|      0|            return string->converted;
  107|      0|        }
  108|  1.96k|    }
  109|       |
  110|  1.96k|    if (lenp) {
  ------------------
  |  Branch (110:9): [True: 0, False: 1.96k]
  ------------------
  111|      0|        *lenp = string->length;
  112|      0|    }
  113|  1.96k|    return string->raw;
  114|  1.96k|}
_zip_string_length:
  131|  1.96k|zip_uint16_t _zip_string_length(const zip_string_t *s) {
  132|  1.96k|    if (s == NULL) {
  ------------------
  |  Branch (132:9): [True: 490, False: 1.47k]
  ------------------
  133|    490|        return 0;
  134|    490|    }
  135|       |
  136|  1.47k|    return s->length;
  137|  1.96k|}
_zip_string_new:
  140|  1.47k|zip_string_t *_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error) {
  141|  1.47k|    zip_string_t *s;
  142|  1.47k|    zip_encoding_type_t expected_encoding;
  143|       |
  144|  1.47k|    if (length == 0) {
  ------------------
  |  Branch (144:9): [True: 0, False: 1.47k]
  ------------------
  145|      0|        return NULL;
  146|      0|    }
  147|       |
  148|  1.47k|    switch (flags & ZIP_FL_ENCODING_ALL) {
  ------------------
  |  |  264|  1.47k|#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  101|  1.47k|#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|  1.47k|#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|  1.47k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  |  |  ------------------
  ------------------
  149|  1.47k|    case ZIP_FL_ENC_GUESS:
  ------------------
  |  |  101|  1.47k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (149:5): [True: 1.47k, False: 0]
  ------------------
  150|  1.47k|        expected_encoding = ZIP_ENCODING_UNKNOWN;
  151|  1.47k|        break;
  152|      0|    case ZIP_FL_ENC_UTF_8:
  ------------------
  |  |  107|      0|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
  |  Branch (152:5): [True: 0, False: 1.47k]
  ------------------
  153|      0|        expected_encoding = ZIP_ENCODING_UTF8_KNOWN;
  154|      0|        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: 1.47k]
  ------------------
  156|      0|        expected_encoding = ZIP_ENCODING_CP437;
  157|      0|        break;
  158|      0|    default:
  ------------------
  |  Branch (158:5): [True: 0, False: 1.47k]
  ------------------
  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|  1.47k|    }
  162|       |
  163|  1.47k|    if ((s = (zip_string_t *)malloc(sizeof(*s))) == NULL) {
  ------------------
  |  Branch (163:9): [True: 0, False: 1.47k]
  ------------------
  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|  1.47k|    if ((s->raw = (zip_uint8_t *)malloc((size_t)length + 1)) == NULL) {
  ------------------
  |  Branch (168:9): [True: 0, False: 1.47k]
  ------------------
  169|      0|        free(s);
  170|      0|        return NULL;
  171|      0|    }
  172|       |
  173|  1.47k|    (void)memcpy_s(s->raw, length + 1, raw, length);
  ------------------
  |  |  200|  1.47k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  174|  1.47k|    s->raw[length] = '\0';
  175|  1.47k|    s->length = length;
  176|  1.47k|    s->encoding = ZIP_ENCODING_UNKNOWN;
  177|  1.47k|    s->converted = NULL;
  178|  1.47k|    s->converted_length = 0;
  179|       |
  180|  1.47k|    if (expected_encoding != ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (180:9): [True: 0, False: 1.47k]
  ------------------
  181|      0|        if (_zip_guess_encoding(s, expected_encoding) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (181:13): [True: 0, False: 0]
  ------------------
  182|      0|            _zip_string_free(s);
  183|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  184|      0|            return NULL;
  185|      0|        }
  186|      0|    }
  187|       |
  188|  1.47k|    return s;
  189|  1.47k|}
_zip_string_write:
  192|  1.47k|int _zip_string_write(zip_t *za, const zip_string_t *s) {
  193|  1.47k|    if (s == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 1.47k]
  ------------------
  194|      0|        return 0;
  195|      0|    }
  196|       |
  197|  1.47k|    return _zip_write(za, s->raw, s->length);
  198|  1.47k|}

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

_zip_guess_encoding:
   99|  4.41k|zip_encoding_type_t _zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding) {
  100|  4.41k|    zip_encoding_type_t enc;
  101|  4.41k|    const zip_uint8_t *name;
  102|  4.41k|    zip_uint32_t i, j, ulen;
  103|  4.41k|    bool can_be_ascii = true;
  104|  4.41k|    bool can_be_utf8 = true;
  105|  4.41k|    bool has_control_characters = false;
  106|       |
  107|  4.41k|    if (str == NULL) {
  ------------------
  |  Branch (107:9): [True: 1.47k, False: 2.94k]
  ------------------
  108|  1.47k|        return ZIP_ENCODING_ASCII;
  109|  1.47k|    }
  110|       |
  111|  2.94k|    name = str->raw;
  112|       |
  113|  2.94k|    if (str->encoding != ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (113:9): [True: 1.47k, False: 1.47k]
  ------------------
  114|  1.47k|        return str->encoding;
  115|  1.47k|    }
  116|       |
  117|  13.2k|    for (i = 0; i < str->length; i++) {
  ------------------
  |  Branch (117:17): [True: 11.7k, False: 1.47k]
  ------------------
  118|  11.7k|        if (name[i] < 128) {
  ------------------
  |  Branch (118:13): [True: 11.7k, False: 0]
  ------------------
  119|  11.7k|            if (name[i] < 32 && name[i] != '\r' && name[i] != '\n' && name[i] != '\t') {
  ------------------
  |  Branch (119:17): [True: 0, False: 11.7k]
  |  Branch (119:33): [True: 0, False: 0]
  |  Branch (119:52): [True: 0, False: 0]
  |  Branch (119:71): [True: 0, False: 0]
  ------------------
  120|      0|                has_control_characters = true;
  121|      0|            }
  122|  11.7k|            continue;
  123|  11.7k|        }
  124|       |
  125|      0|        can_be_ascii = false;
  126|      0|        if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) {
  ------------------
  |  |   89|      0|#define UTF_8_LEN_2_MASK 0xe0
  ------------------
                      if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) {
  ------------------
  |  |   90|      0|#define UTF_8_LEN_2_MATCH 0xc0
  ------------------
  |  Branch (126:13): [True: 0, False: 0]
  ------------------
  127|      0|            ulen = 1;
  128|      0|        }
  129|      0|        else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) {
  ------------------
  |  |   91|      0|#define UTF_8_LEN_3_MASK 0xf0
  ------------------
                      else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) {
  ------------------
  |  |   92|      0|#define UTF_8_LEN_3_MATCH 0xe0
  ------------------
  |  Branch (129:18): [True: 0, False: 0]
  ------------------
  130|      0|            ulen = 2;
  131|      0|        }
  132|      0|        else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) {
  ------------------
  |  |   93|      0|#define UTF_8_LEN_4_MASK 0xf8
  ------------------
                      else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) {
  ------------------
  |  |   94|      0|#define UTF_8_LEN_4_MATCH 0xf0
  ------------------
  |  Branch (132:18): [True: 0, False: 0]
  ------------------
  133|      0|            ulen = 3;
  134|      0|        }
  135|      0|        else {
  136|      0|            can_be_utf8 = false;
  137|      0|            break;
  138|      0|        }
  139|       |
  140|      0|        if (i + ulen >= str->length) {
  ------------------
  |  Branch (140:13): [True: 0, False: 0]
  ------------------
  141|      0|            can_be_utf8 = false;
  142|      0|            break;
  143|      0|        }
  144|       |
  145|      0|        for (j = 1; j <= ulen; j++) {
  ------------------
  |  Branch (145:21): [True: 0, False: 0]
  ------------------
  146|      0|            if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
  ------------------
  |  |   95|      0|#define UTF_8_CONTINUE_MASK 0xc0
  ------------------
                          if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  |  Branch (146:17): [True: 0, False: 0]
  ------------------
  147|      0|                can_be_utf8 = false;
  148|      0|                goto done;
  149|      0|            }
  150|      0|        }
  151|      0|        i += ulen;
  152|      0|    }
  153|       |
  154|  1.47k|done:
  155|  1.47k|    enc = ZIP_ENCODING_CP437;
  156|       |
  157|  1.47k|    switch (expected_encoding) {
  ------------------
  |  Branch (157:13): [True: 1.47k, False: 0]
  ------------------
  158|      0|    case ZIP_ENCODING_UTF8_KNOWN:
  ------------------
  |  Branch (158:5): [True: 0, False: 1.47k]
  ------------------
  159|      0|    case ZIP_ENCODING_UTF8_GUESSED:
  ------------------
  |  Branch (159:5): [True: 0, False: 1.47k]
  ------------------
  160|      0|        if (can_be_utf8) {
  ------------------
  |  Branch (160:13): [True: 0, False: 0]
  ------------------
  161|      0|            enc = ZIP_ENCODING_UTF8_KNOWN;
  162|      0|        }
  163|      0|        else {
  164|      0|            enc = ZIP_ENCODING_ERROR;
  165|      0|        }
  166|      0|        break;
  167|       |
  168|      0|    case ZIP_ENCODING_ASCII:
  ------------------
  |  Branch (168:5): [True: 0, False: 1.47k]
  ------------------
  169|      0|        if (can_be_ascii && !has_control_characters) {
  ------------------
  |  Branch (169:13): [True: 0, False: 0]
  |  Branch (169:29): [True: 0, False: 0]
  ------------------
  170|      0|            enc = ZIP_ENCODING_ASCII;
  171|      0|        }
  172|      0|        else {
  173|      0|            enc = ZIP_ENCODING_ERROR;
  174|      0|        }
  175|      0|        break;
  176|       |
  177|      0|    case ZIP_ENCODING_CP437:
  ------------------
  |  Branch (177:5): [True: 0, False: 1.47k]
  ------------------
  178|      0|        enc = ZIP_ENCODING_CP437;
  179|      0|        break;
  180|       |
  181|  1.47k|    case ZIP_ENCODING_UNKNOWN:
  ------------------
  |  Branch (181:5): [True: 1.47k, False: 0]
  ------------------
  182|  1.47k|        if (can_be_ascii && !has_control_characters) {
  ------------------
  |  Branch (182:13): [True: 1.47k, False: 0]
  |  Branch (182:29): [True: 1.47k, False: 0]
  ------------------
  183|       |            /* only bytes from 0x20-0x7F */
  184|  1.47k|            enc = ZIP_ENCODING_ASCII;
  185|  1.47k|        }
  186|      0|        else if (can_be_ascii && has_control_characters) {
  ------------------
  |  Branch (186:18): [True: 0, False: 0]
  |  Branch (186:34): [True: 0, False: 0]
  ------------------
  187|       |            /* only bytes from 0x00-0x7F */
  188|      0|            enc = ZIP_ENCODING_CP437;
  189|      0|        }
  190|      0|        else if (can_be_utf8) {
  ------------------
  |  Branch (190:18): [True: 0, False: 0]
  ------------------
  191|       |            /* contains bytes from 0x80-0xFF and is valid UTF-8 */
  192|      0|            enc = ZIP_ENCODING_UTF8_GUESSED;
  193|      0|        }
  194|      0|        else {
  195|       |            /* fallback */
  196|      0|            enc = ZIP_ENCODING_CP437;
  197|      0|        }
  198|  1.47k|        break;
  199|      0|    case ZIP_ENCODING_ERROR:
  ------------------
  |  Branch (199:5): [True: 0, False: 1.47k]
  ------------------
  200|       |        /* invalid, shouldn't happen */
  201|      0|        enc = ZIP_ENCODING_ERROR;
  202|      0|        break;
  203|  1.47k|    }
  204|       |
  205|  1.47k|    str->encoding = enc;
  206|  1.47k|    return enc;
  207|  1.47k|}

LLVMFuzzerTestOneInput:
   23|    490|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   24|    490|    const char *path = "test_pkware.zip";
   25|    490|    const char *password = "password";
   26|    490|    const char *file = "filename";
   27|    490|    int error = 0;
   28|    490|    struct zip *archive;
   29|       |
   30|    490|    (void)remove(path);
   31|    490|    if ((archive = zip_open(path, ZIP_CREATE, &error)) == NULL) {
  ------------------
  |  |   86|    490|#define ZIP_CREATE 1
  ------------------
  |  Branch (31:9): [True: 0, False: 490]
  ------------------
   32|      0|        return -1;
   33|      0|    }
   34|       |
   35|    490|    struct zip_source *source = zip_source_buffer(archive, data, size, 0);
   36|    490|    if (source == NULL) {
  ------------------
  |  Branch (36:9): [True: 0, False: 490]
  ------------------
   37|      0|        fprintf(stderr, "failed to create source buffer. %s\n", zip_strerror(archive));
   38|      0|        zip_discard(archive);
   39|      0|        return -1;
   40|      0|    }
   41|       |
   42|    490|    int index = (int)zip_file_add(archive, file, source, ZIP_FL_OVERWRITE);
  ------------------
  |  |  109|    490|#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
  ------------------
   43|    490|    if (index < 0) {
  ------------------
  |  Branch (43:9): [True: 0, False: 490]
  ------------------
   44|      0|        fprintf(stderr, "failed to add file to archive: %s\n", zip_strerror(archive));
   45|      0|        zip_discard(archive);
   46|      0|        return -1;
   47|      0|    }
   48|    490|    if (zip_file_set_encryption(archive, index, ZIP_EM_TRAD_PKWARE, password) < 0) {
  ------------------
  |  |  208|    490|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (48:9): [True: 0, False: 490]
  ------------------
   49|      0|        fprintf(stderr, "failed to set file encryption: %s\n", zip_strerror(archive));
   50|      0|        zip_discard(archive);
   51|      0|        return -1;
   52|      0|    }
   53|    490|    if (zip_close(archive) < 0) {
  ------------------
  |  Branch (53:9): [True: 0, False: 490]
  ------------------
   54|      0|        fprintf(stderr, "error closing archive: %s\n", zip_strerror(archive));
   55|      0|        zip_discard(archive);
   56|      0|        return -1;
   57|      0|    }
   58|    490|    (void)remove(path);
   59|       |
   60|    490|    return 0;
   61|    490|}

