Add some casts for gcc 4.8.3 with more-than-default warnings enabled.
diff --git a/lib/zip.h b/lib/zip.h
index 3b51208..88a44a4 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -236,6 +236,7 @@
zip_int64_t offset;
int whence;
};
+
typedef struct zip_source_args_seek zip_source_args_seek_t;
#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), NULL : (type *)(data))
diff --git a/lib/zip_close.c b/lib/zip_close.c
index 5047088..9502273 100644
--- a/lib/zip_close.c
+++ b/lib/zip_close.c
@@ -207,7 +207,7 @@
zip_uint64_t offset;
/* when copying data, all sizes are known -> no data descriptor needed */
- de->bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
+ de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR;
if (_zip_dirent_write(za, de, ZIP_FL_LOCAL) < 0) {
error = 1;
break;
@@ -306,7 +306,7 @@
}
/* as long as we don't support non-seekable output, clear data descriptor bit */
- de->bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
+ de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR;
if ((is_zip64=_zip_dirent_write(za, de, flags)) < 0)
return -1;
diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c
index d26d54b..d95d07a 100644
--- a/lib/zip_dirent.c
+++ b/lib/zip_dirent.c
@@ -42,7 +42,7 @@
#include "zipint.h"
static time_t _zip_d2u_time(zip_uint16_t, zip_uint16_t);
-static struct zip_string *_zip_dirent_process_ef_utf_8(const struct zip_dirent *, zip_uint16_t, struct zip_string *);
+static struct zip_string *_zip_dirent_process_ef_utf_8(const struct zip_dirent *de, zip_uint16_t id, struct zip_string *str);
static struct zip_extra_field *_zip_ef_utf8(zip_uint16_t, struct zip_string *, struct zip_error *);
@@ -399,7 +399,7 @@
zde->extra_fields = NULL;
zde->comment = NULL;
- size += filename_len+ef_len+comment_len;
+ size += (zip_uint32_t)filename_len+ef_len+comment_len;
if (leftp && (*leftp < size)) {
zip_error_set(error, ZIP_ER_INCONS, 0);
@@ -456,7 +456,8 @@
/* Zip64 */
if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
- zip_uint16_t got_len, needed_len;
+ zip_uint32_t needed_len;
+ zip_uint16_t got_len;
const zip_uint8_t *ef = _zip_ef_get_by_id(zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
/* TODO: if got_len == 0 && !ZIP64_EOCD: no error, 0xffffffff is valid value */
if (ef == NULL)
@@ -465,9 +466,17 @@
if (local)
needed_len = 16;
- else
- needed_len = ((zde->uncomp_size == ZIP_UINT32_MAX) + (zde->comp_size == ZIP_UINT32_MAX) + (zde->offset == ZIP_UINT32_MAX)) * 8
- + (zde->disk_number == ZIP_UINT16_MAX) * 4;
+ else {
+ needed_len = 0;
+ if (zde->uncomp_size == ZIP_UINT32_MAX)
+ needed_len += 8;
+ if (zde->comp_size == ZIP_UINT32_MAX)
+ needed_len += 8;
+ if (zde->offset == ZIP_UINT32_MAX)
+ needed_len += 8;
+ if (zde->disk_number == ZIP_UINT16_MAX)
+ needed_len += 4;
+ }
if (got_len != needed_len) {
zip_error_set(error, ZIP_ER_INCONS, 0);
@@ -520,7 +529,7 @@
ef_crc = _zip_get_32(&ef);
if (_zip_string_crc32(str) == ef_crc) {
- struct zip_string *ef_str = _zip_string_new(ef, ef_len-5, ZIP_FL_ENC_UTF_8, NULL);
+ struct zip_string *ef_str = _zip_string_new(ef, (zip_uint16_t)(ef_len-5), ZIP_FL_ENC_UTF_8, NULL);
if (ef_str != NULL) {
_zip_string_free(str);
@@ -651,7 +660,7 @@
(name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_UTF8_KNOWN))
de->bitflags |= ZIP_GPBF_ENCODING_UTF_8;
else {
- de->bitflags &= ~ZIP_GPBF_ENCODING_UTF_8;
+ de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCODING_UTF_8;
if (name_enc == ZIP_ENCODING_UTF8_KNOWN) {
ef = _zip_ef_utf8(ZIP_EF_UTF_8_NAME, de->filename, &za->error);
if (ef == NULL)
@@ -719,7 +728,7 @@
_zip_put_32(&p, ZIP_UINT32_MAX);
_zip_put_16(&p, _zip_string_length(de->filename));
- _zip_put_16(&p, _zip_ef_size(de->extra_fields, flags) + _zip_ef_size(ef, ZIP_EF_BOTH));
+ _zip_put_16(&p, (zip_uint16_t)(_zip_ef_size(de->extra_fields, flags) + _zip_ef_size(ef, ZIP_EF_BOTH)));
if ((flags & ZIP_FL_LOCAL) == 0) {
_zip_put_16(&p, _zip_string_length(de->comment));
diff --git a/lib/zip_extra_field.c b/lib/zip_extra_field.c
index 85cab50..74cf2be 100644
--- a/lib/zip_extra_field.c
+++ b/lib/zip_extra_field.c
@@ -287,7 +287,7 @@
size = 0;
for (; ef; ef=ef->next) {
if (ef->flags & flags & ZIP_EF_BOTH)
- size += 4+ef->size;
+ size = (zip_uint16_t)(size+4+ef->size);
}
return size;
diff --git a/lib/zip_file_get_external_attributes.c b/lib/zip_file_get_external_attributes.c
index bf8bf02..a7c6455 100644
--- a/lib/zip_file_get_external_attributes.c
+++ b/lib/zip_file_get_external_attributes.c
@@ -42,7 +42,7 @@
return -1;
if (opsys)
- *opsys = (de->version_madeby >> 8) & 0xff;
+ *opsys = (zip_uint8_t)((de->version_madeby >> 8) & 0xff);
if (attributes)
*attributes = de->ext_attrib;
diff --git a/lib/zip_file_set_external_attributes.c b/lib/zip_file_set_external_attributes.c
index 61623d2..c06891f 100644
--- a/lib/zip_file_set_external_attributes.c
+++ b/lib/zip_file_set_external_attributes.c
@@ -51,7 +51,7 @@
e = za->entry+idx;
- unchanged_opsys = e->orig ? e->orig->version_madeby>>8 : ZIP_OPSYS_DEFAULT;
+ unchanged_opsys = e->orig ? (zip_uint8_t)(e->orig->version_madeby>>8) : ZIP_OPSYS_DEFAULT;
unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT;
changed = (opsys != unchanged_opsys || attributes != unchanged_attributes);
@@ -63,7 +63,7 @@
return -1;
}
}
- e->changes->version_madeby = (zip_uint16_t)(opsys << 8) | (e->changes->version_madeby & 0xff);
+ e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff));
e->changes->ext_attrib = attributes;
e->changes->changed |= ZIP_DIRENT_ATTRIBUTES;
}
@@ -74,7 +74,8 @@
e->changes = NULL;
}
else {
- e->changes->version_madeby = (zip_uint16_t)(unchanged_opsys << 8) | (e->changes->version_madeby & 0xff);
+ e->changes->version_madeby = (zip_uint16_t)((unchanged_opsys << 8) | (e->changes->version_madeby & 0xff))
+;
e->changes->ext_attrib = unchanged_attributes;
}
}
diff --git a/lib/zip_io_util.c b/lib/zip_io_util.c
index 08d498e..6664ecd 100644
--- a/lib/zip_io_util.c
+++ b/lib/zip_io_util.c
@@ -156,32 +156,32 @@
void
_zip_put_16(zip_uint8_t **p, zip_uint16_t i)
{
- *((*p)++) = i&0xff;
- *((*p)++) = (i>>8)&0xff;
+ *((*p)++) = (zip_uint8_t)(i&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>8)&0xff);
}
void
_zip_put_32(zip_uint8_t **p, zip_uint32_t i)
{
- *((*p)++) = i&0xff;
- *((*p)++) = (i>>8)&0xff;
- *((*p)++) = (i>>16)&0xff;
- *((*p)++) = (i>>24)&0xff;
+ *((*p)++) = (zip_uint8_t)(i&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>8)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>16)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>24)&0xff);
}
void
_zip_put_64(zip_uint8_t **p, zip_uint64_t i)
{
- *((*p)++) = i&0xff;
- *((*p)++) = (i>>8)&0xff;
- *((*p)++) = (i>>16)&0xff;
- *((*p)++) = (i>>24)&0xff;
- *((*p)++) = (i>>32)&0xff;
- *((*p)++) = (i>>40)&0xff;
- *((*p)++) = (i>>48)&0xff;
- *((*p)++) = (i>>56)&0xff;
+ *((*p)++) = (zip_uint8_t)(i&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>8)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>16)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>24)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>32)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>40)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>48)&0xff);
+ *((*p)++) = (zip_uint8_t)((i>>56)&0xff);
}
diff --git a/lib/zip_source_buffer.c b/lib/zip_source_buffer.c
index 85631ad..d3e1301 100644
--- a/lib/zip_source_buffer.c
+++ b/lib/zip_source_buffer.c
@@ -31,7 +31,7 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -122,8 +122,6 @@
read_data(void *state, void *data, zip_uint64_t len, enum zip_source_cmd cmd)
{
struct read_data *ctx = (struct read_data *)state;
- char *buf;
- zip_uint64_t n;
switch (cmd) {
case ZIP_SOURCE_BEGIN_WRITE:
@@ -156,6 +154,10 @@
return 0;
case ZIP_SOURCE_READ:
+ if (len > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
return buffer_read(ctx->in, data, len);
case ZIP_SOURCE_REMOVE:
@@ -208,12 +210,25 @@
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_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, -1);
case ZIP_SOURCE_TELL:
- return ctx->in->offset;
+ if (ctx->in->offset > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
+ return -1;
+ }
+ return (zip_int64_t)ctx->in->offset;
+
case ZIP_SOURCE_TELL_WRITE:
- return ctx->out->offset;
+ if (ctx->out->offset > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
+ return -1;
+ }
+ return (zip_int64_t)ctx->out->offset;
case ZIP_SOURCE_WRITE:
+ if (len > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
return buffer_write(ctx->out, data, len, &ctx->error);
default:
@@ -321,6 +336,9 @@
if (length == 0) {
return 0;
}
+ if (length > ZIP_INT64_MAX) {
+ return -1;
+ }
i = buffer->offset / buffer->fragment_size;
fragment_offset = buffer->offset % buffer->fragment_size;
@@ -336,30 +354,30 @@
}
buffer->offset += n;
- return n;
+ return (zip_int64_t)n;
}
static int
buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error)
{
- zip_uint64_t offset;
+ zip_int64_t offset;
zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, error);
if (args == NULL)
return -1;
-
+
switch (args->whence) {
case SEEK_CUR:
- offset = buffer->offset + args->offset;
+ offset = (zip_int64_t)buffer->offset + args->offset;
break;
case SEEK_END:
- offset = buffer->size + args->offset;
+ offset = (zip_int64_t)buffer->size + args->offset;
break;
case SEEK_SET:
- offset = args->offset;
+ offset = (zip_int64_t)args->offset;
break;
}
@@ -368,7 +386,7 @@
return -1;
}
- buffer->offset = offset;
+ buffer->offset = (zip_uint64_t)offset;
return 0;
}
@@ -432,5 +450,5 @@
buffer->size = buffer->offset;
}
- return n;
+ return (zip_int64_t)n;
}
diff --git a/lib/zip_source_crc.c b/lib/zip_source_crc.c
index f96cb3e..8e2edc2 100644
--- a/lib/zip_source_crc.c
+++ b/lib/zip_source_crc.c
@@ -122,8 +122,8 @@
else {
zip_uint64_t i, nn;
- for (i=0; i < n; i += nn) {
- nn = ZIP_MIN(UINT_MAX, n-i);
+ for (i=0; i < (zip_uint64_t)n; i += nn) {
+ nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n-i);
ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data+i, (uInt)nn);
}
diff --git a/lib/zip_source_deflate.c b/lib/zip_source_deflate.c
index a3a9cef..42d0155 100644
--- a/lib/zip_source_deflate.c
+++ b/lib/zip_source_deflate.c
@@ -192,7 +192,7 @@
return 0;
out_offset = 0;
- out_len = ZIP_MIN(UINT_MAX, len);
+ out_len = (uInt)ZIP_MIN(UINT_MAX, len);
ctx->zstr.next_out = (Bytef *)data;
ctx->zstr.avail_out = out_len;
diff --git a/lib/zip_source_pkware.c b/lib/zip_source_pkware.c
index c88ae02..21a826e 100644
--- a/lib/zip_source_pkware.c
+++ b/lib/zip_source_pkware.c
@@ -107,8 +107,8 @@
if (!update_only) {
/* decrypt next byte */
tmp = (zip_uint16_t)(ctx->key[2] | 2);
- tmp = (tmp * (tmp ^ 1)) >> 8;
- b ^= tmp;
+ tmp = (zip_uint16_t)((tmp * (tmp ^ 1)) >> 8);
+ b ^= (Bytef)tmp;
}
/* store cleartext */
@@ -118,7 +118,7 @@
/* update keys */
ctx->key[0] = (zip_uint32_t)crc32(ctx->key[0] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL;
ctx->key[1] = (ctx->key[1] + (ctx->key[0] & 0xff)) * 134775813 + 1;
- b = ctx->key[1] >> 24;
+ b = (Bytef)(ctx->key[1] >> 24);
ctx->key[2] = (zip_uint32_t)crc32(ctx->key[2] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL;
}
}
diff --git a/lib/zip_source_window.c b/lib/zip_source_window.c
index 5bbfdfe..ca5359c 100644
--- a/lib/zip_source_window.c
+++ b/lib/zip_source_window.c
@@ -77,7 +77,7 @@
zip_stat_init(&ctx->stat);
zip_error_init(&ctx->error);
ctx->supports = (zip_source_supports(src) & 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_SEEK, ZIP_SOURCE_TELL, -1)) | (zip_source_make_command_bitmap(ZIP_SOURCE_TELL, -1));
- ctx->needs_seek = ctx->supports & zip_source_make_command_bitmap(ZIP_SOURCE_SEEK, -1);
+ ctx->needs_seek = (zip_int16_t)(ctx->supports & zip_source_make_command_bitmap(ZIP_SOURCE_SEEK, -1));
if (st) {
if (_zip_stat_merge(&ctx->stat, st, error) < 0) {
diff --git a/lib/zip_string.c b/lib/zip_string.c
index a731ebb..d00e3aa 100644
--- a/lib/zip_string.c
+++ b/lib/zip_string.c
@@ -154,7 +154,7 @@
return NULL;
}
- if ((s->raw=(zip_uint8_t *)malloc(length+1)) == NULL) {
+ if ((s->raw=(zip_uint8_t *)malloc((size_t)(length+1))) == NULL) {
free(s);
return NULL;
}
diff --git a/lib/zip_utf-8.c b/lib/zip_utf-8.c
index 58c4195..4321412 100644
--- a/lib/zip_utf-8.c
+++ b/lib/zip_utf-8.c
@@ -196,20 +196,20 @@
return 1;
}
if (codepoint < 0x0800) {
- buf[0] = UTF_8_LEN_2_MATCH | ((codepoint >> 6) & 0x1f);
- buf[1] = UTF_8_CONTINUE_MATCH | (codepoint & 0x3f);
+ buf[0] = (zip_uint8_t)(UTF_8_LEN_2_MATCH | ((codepoint >> 6) & 0x1f));
+ buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
return 2;
}
if (codepoint < 0x10000) {
- buf[0] = UTF_8_LEN_3_MATCH | ((codepoint >> 12) & 0x0f);
- buf[1] = UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f);
- buf[2] = UTF_8_CONTINUE_MATCH | (codepoint & 0x3f);
+ buf[0] = (zip_uint8_t)(UTF_8_LEN_3_MATCH | ((codepoint >> 12) & 0x0f));
+ buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f));
+ buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
return 3;
}
- buf[0] = UTF_8_LEN_4_MATCH | ((codepoint >> 18) & 0x07);
- buf[1] = UTF_8_CONTINUE_MATCH | ((codepoint >> 12) & 0x3f);
- buf[2] = UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f);
- buf[3] = UTF_8_CONTINUE_MATCH | (codepoint & 0x3f);
+ buf[0] = (zip_uint8_t)(UTF_8_LEN_4_MATCH | ((codepoint >> 18) & 0x07));
+ buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 12) & 0x3f));
+ buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f));
+ buf[3] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
return 4;
}
diff --git a/regress/modify.c b/regress/modify.c
index c5df6cf..9debe2a 100644
--- a/regress/modify.c
+++ b/regress/modify.c
@@ -55,7 +55,6 @@
int (*function)(int argc, char *argv[]);
} dispatch_table_t;
-const char *prg;
static zip_flags_t get_flags(const char *arg);
static zip_int32_t get_compression_method(const char *arg);
static void hexdump(const zip_uint8_t *data, zip_uint16_t len);
@@ -133,7 +132,7 @@
return -1;
}
if ((zs=zip_source_zip(za, z_in, idx, 0, start, len)) == NULL) {
- fprintf(stderr, "error creating file source from '%s' index '%d': %s\n", argv[1], idx, zip_strerror(za));
+ fprintf(stderr, "error creating file source from '%s' index '%" PRIu64 "': %s\n", argv[1], idx, zip_strerror(za));
zip_close(z_in);
return -1;
}
@@ -154,7 +153,7 @@
idx = strtoull(argv[0], NULL, 10);
ceflags = get_flags(argv[1]);
if ((count=zip_file_extra_fields_count(za, idx, ceflags)) < 0) {
- fprintf(stderr, "can't get extra field count for file at index '%d': %s\n", idx, zip_strerror(za));
+ fprintf(stderr, "can't get extra field count for file at index '%" PRIu64 "': %s\n", idx, zip_strerror(za));
return -1;
} else {
printf("Extra field count: %d\n", count);
@@ -164,14 +163,15 @@
static int
count_extra_by_id(int argc, char *argv[]) {
- zip_int16_t count, eid;
+ zip_int16_t count;
+ zip_uint16_t eid;
zip_flags_t ceflags = 0;
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
- eid = strtoull(argv[1], NULL, 10);
+ eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
ceflags = get_flags(argv[2]);
if ((count=zip_file_extra_fields_count_by_id(za, idx, eid, ceflags)) < 0) {
- fprintf(stderr, "can't get extra field count for file at index '%d' and for id `%d': %s\n", idx, eid, zip_strerror(za));
+ fprintf(stderr, "can't get extra field count for file at index '%" PRIu64 "' and for id `%d': %s\n", idx, eid, zip_strerror(za));
return -1;
} else {
printf("Extra field count: %d\n", count);
@@ -184,7 +184,7 @@
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
if (zip_delete(za, idx) < 0) {
- fprintf(stderr, "can't delete file at index '%d': %s\n", idx, zip_strerror(za));
+ fprintf(stderr, "can't delete file at index '%" PRIu64 "': %s\n", idx, zip_strerror(za));
return -1;
}
return 0;
@@ -196,10 +196,10 @@
zip_uint16_t eid;
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
- eid = strtoull(argv[1], NULL, 10);
+ eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
geflags = get_flags(argv[2]);
if ((zip_file_extra_field_delete(za, idx, eid, geflags)) < 0) {
- fprintf(stderr, "can't delete extra field data for file at index '%d', extra field id `%d': %s\n", idx, eid, zip_strerror(za));
+ fprintf(stderr, "can't delete extra field data for file at index '%" PRIu64 "', extra field id `%d': %s\n", idx, eid, zip_strerror(za));
return -1;
}
return 0;
@@ -211,11 +211,11 @@
zip_uint16_t eid, eidx;
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
- eid = strtoull(argv[1], NULL, 10);
- eidx = strtoull(argv[2], NULL, 10);
+ eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
+ eidx = (zip_uint16_t)strtoull(argv[2], NULL, 10);
geflags = get_flags(argv[3]);
if ((zip_file_extra_field_delete_by_id(za, idx, eid, eidx, geflags)) < 0) {
- fprintf(stderr, "can't delete extra field data for file at index '%d', extra field id `%d', extra field idx `%d': %s\n", idx, eid, eidx, zip_strerror(za));
+ fprintf(stderr, "can't delete extra field data for file at index '%" PRIu64 "', extra field id `%d', extra field idx `%d': %s\n", idx, eid, eidx, zip_strerror(za));
return -1;
}
return 0;
@@ -241,10 +241,10 @@
zip_uint64_t idx;
/* get extra field data */
idx = strtoull(argv[0], NULL, 10);
- eidx = strtoull(argv[1], NULL, 10);
+ eidx = (zip_uint16_t)strtoull(argv[1], NULL, 10);
geflags = get_flags(argv[2]);
if ((efdata=zip_file_extra_field_get(za, idx, eidx, &id, &eflen, geflags)) == NULL) {
- fprintf(stderr, "can't get extra field data for file at index %d, extra field %d, flags %u: %s\n", idx, eidx, geflags, zip_strerror(za));
+ fprintf(stderr, "can't get extra field data for file at index %" PRIu64 ", extra field %d, flags %u: %s\n", idx, eidx, geflags, zip_strerror(za));
return -1;
}
printf("Extra field 0x%04x: len %d", id, eflen);
@@ -263,11 +263,11 @@
const zip_uint8_t *efdata;
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
- eid = strtoull(argv[1], NULL, 10);
- eidx = strtoull(argv[2], NULL, 10);
+ eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
+ eidx = (zip_uint16_t)strtoull(argv[2], NULL, 10);
geflags = get_flags(argv[3]);
if ((efdata=zip_file_extra_field_get_by_id(za, idx, eid, eidx, &eflen, geflags)) == NULL) {
- fprintf(stderr, "can't get extra field data for file at index %d, extra field id %d, ef index %d, flags %u: %s\n", idx, eid, eidx, geflags, zip_strerror(za));
+ fprintf(stderr, "can't get extra field data for file at index %" PRIu64 ", extra field id %d, ef index %d, flags %u: %s\n", idx, eid, eidx, geflags, zip_strerror(za));
return -1;
}
printf("Extra field 0x%04x: len %d", eid, eflen);
@@ -301,7 +301,7 @@
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
if (zip_rename(za, idx, argv[1]) < 0) {
- fprintf(stderr, "can't rename file at index '%d' to `%s': %s\n", idx, argv[1], zip_strerror(za));
+ fprintf(stderr, "can't rename file at index '%" PRIu64 "' to `%s': %s\n", idx, argv[1], zip_strerror(za));
return -1;
}
return 0;
@@ -331,12 +331,12 @@
const zip_uint8_t *efdata;
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
- eid = strtoull(argv[1], NULL, 10);
- eidx = strtoull(argv[2], NULL, 10);
+ eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
+ eidx = (zip_uint16_t)strtoull(argv[2], NULL, 10);
geflags = get_flags(argv[3]);
efdata = (zip_uint8_t *)argv[4];
if ((zip_file_extra_field_set(za, idx, eid, eidx, efdata, (zip_uint16_t)strlen((const char *)efdata), geflags)) < 0) {
- fprintf(stderr, "can't set extra field data for file at index '%d', extra field id `%d', index `%d': %s\n", idx, eid, eidx, zip_strerror(za));
+ fprintf(stderr, "can't set extra field data for file at index '%" PRIu64 "', extra field id `%d', index `%d': %s\n", idx, eid, eidx, zip_strerror(za));
return -1;
}
return 0;
@@ -347,7 +347,7 @@
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
if (zip_file_set_comment(za, idx, argv[1], (zip_uint16_t)strlen(argv[1]), 0) < 0) {
- fprintf(stderr, "can't set file comment at index '%d' to `%s': %s\n", idx, argv[1], zip_strerror(za));
+ fprintf(stderr, "can't set file comment at index '%" PRIu64 "' to `%s': %s\n", idx, argv[1], zip_strerror(za));
return -1;
}
return 0;
@@ -360,9 +360,9 @@
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
method = get_compression_method(argv[1]);
- flags = strtoull(argv[2], NULL, 10);
+ flags = (zip_uint32_t)strtoull(argv[2], NULL, 10);
if (zip_set_file_compression(za, idx, method, flags) < 0) {
- fprintf(stderr, "can't set file compression method at index '%d' to `%s', flags `%d': %s\n", idx, argv[1], flags, zip_strerror(za));
+ fprintf(stderr, "can't set file compression method at index '%" PRIu64 "' to `%s', flags `%d': %s\n", idx, argv[1], flags, zip_strerror(za));
return -1;
}
return 0;
@@ -374,9 +374,9 @@
time_t mtime;
zip_uint64_t idx;
idx = strtoull(argv[0], NULL, 10);
- mtime = strtoull(argv[1], NULL, 10);
+ mtime = (time_t)strtoull(argv[1], NULL, 10);
if (zip_file_set_mtime(za, idx, mtime, 0) < 0) {
- fprintf(stderr, "can't set file mtime at index '%d' to `%ld': %s\n", idx, mtime, zip_strerror(za));
+ fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to `%ld': %s\n", idx, mtime, zip_strerror(za));
return -1;
}
return 0;
@@ -384,7 +384,7 @@
static int
zstat(int argc, char *argv[]) {
- int index;
+ zip_uint64_t index;
char buf[100];
struct zip_stat sb;
index = strtoull(argv[0], NULL, 10);
@@ -476,7 +476,7 @@
{
struct stat st;
zip_source_t *src;
- zip_t *za;
+ zip_t *zb;
zip_error_t error;
if (stat(archive, &st) < 0) {
@@ -491,7 +491,7 @@
else {
char *buf;
FILE *fp;
- if ((buf=malloc(st.st_size)) == NULL) {
+ if ((buf=malloc((size_t)st.st_size)) == NULL) {
*err = ZIP_ER_MEMORY;
return NULL;
}
@@ -500,13 +500,13 @@
*err = ZIP_ER_READ;
return NULL;
}
- if (fread(buf, st.st_size, 1, fp) < 1) {
+ if (fread(buf, (size_t)st.st_size, 1, fp) < 1) {
free(buf);
*err = ZIP_ER_READ;
return NULL;
}
fclose(fp);
- src = zip_source_buffer_create(buf, st.st_size, 1, &error);
+ src = zip_source_buffer_create(buf, (zip_uint64_t)st.st_size, 1, &error);
if (src == NULL) {
free(buf);
}
@@ -516,8 +516,8 @@
errno = zip_error_code_system(&error);
return NULL;
}
- za = zip_open_from_source(src, flags, &error);
- if (za == NULL) {
+ zb = zip_open_from_source(src, flags, &error);
+ if (zb == NULL) {
*err = zip_error_code_zip(&error);
errno = zip_error_code_system(&error);
zip_source_free(src);
@@ -525,7 +525,7 @@
}
zip_source_keep(src);
*srcp = src;
- return za;
+ return zb;
}
static int
@@ -555,7 +555,7 @@
zip_source_close(src);
return -1;
}
- if (zip_source_read(src, buf, zst.size) < zst.size) {
+ if (zip_source_read(src, buf, zst.size) < (zip_int64_t)zst.size) {
fprintf(stderr, "zip_source_read on buffer failed: %s\n", zip_error_strerror(zip_source_error(src)));
zip_source_close(src);
free(buf);
@@ -607,7 +607,7 @@
int
dispatch(int argc, char *argv[])
{
- int i;
+ unsigned int i;
for (i=0; i<sizeof(dispatch_table)/sizeof(dispatch_table_t); i++) {
if (strcmp(dispatch_table[i].cmdline_name, argv[0]) == 0) {
argc--;
@@ -629,9 +629,9 @@
void
-usage(const char *prg)
+usage(const char *progname)
{
- int i;
+ unsigned int i;
fprintf(stderr, "usage: %s [-cemnt] archive command1 [args] [command2 [args] ...]\n\n"
"Supported options are:\n"
"\t-c\tcheck consistency\n"
@@ -641,7 +641,7 @@
"\t-n\tcreate archive if it doesn't exist (default)\n"
"\t-r\tprint raw file name encoding without translation (for stat)\n"
"\t-s\tfollow file name convention strictly (for stat)\n"
- "\t-t\tdisregard current archive contents, if any\n", prg);
+ "\t-t\tdisregard current archive contents, if any\n", progname);
fprintf(stderr, "\nSupported commands and arguments are:\n");
for (i=0; i<sizeof(dispatch_table)/sizeof(dispatch_table_t); i++) {
fprintf(stderr, "\t%s %s -- %s\n", dispatch_table[i].cmdline_name, dispatch_table[i].arg_names, dispatch_table[i].description);
@@ -654,9 +654,10 @@
main(int argc, char *argv[])
{
const char *archive;
- struct zip_source *zs, *memory_src;
+ struct zip_source *memory_src;
char buf[100];
- int c, arg, err, flags, idx, in_memory;
+ int c, arg, err, flags, in_memory;
+ const char *prg;
flags = 0;
in_memory = 0;
diff --git a/src/zipcmp.c b/src/zipcmp.c
index cba5f75..2d67eed 100644
--- a/src/zipcmp.c
+++ b/src/zipcmp.c
@@ -359,7 +359,7 @@
}
a->entry[a->nentry].name = strdup(ent->fts_path+prefix_length);
- a->entry[a->nentry].size = ent->fts_statp->st_size;
+ a->entry[a->nentry].size = (zip_uint64_t)ent->fts_statp->st_size;
if ((crc = compute_crc(ent->fts_accpath)) < 0) {
fts_close(fts);
return -1;
@@ -515,27 +515,29 @@
ef_read(struct zip *za, zip_uint64_t idx, struct entry *e)
{
zip_int16_t n_local, n_central;
- int i;
+ zip_uint16_t i;
if ((n_local = zip_file_extra_fields_count(za, idx, ZIP_FL_LOCAL)) < 0
|| (n_central = zip_file_extra_fields_count(za, idx, ZIP_FL_CENTRAL)) < 0) {
return -1;
}
- e->n_extra_fields = (zip_uint16_t)n_local + (zip_uint16_t)n_central;
+ e->n_extra_fields = (zip_uint16_t)(n_local + n_central);
if ((e->extra_fields=(struct ef *)malloc(sizeof(e->extra_fields[0])*e->n_extra_fields)) == NULL)
return -1;
for (i=0; i<n_local; i++) {
e->extra_fields[i].name = e->name;
- if ((e->extra_fields[i].data=zip_file_extra_field_get(za, idx, i, &e->extra_fields[i].id, &e->extra_fields[i].size, ZIP_FL_LOCAL)) == NULL)
+ e->extra_fields[i].data = zip_file_extra_field_get(za, idx, i, &e->extra_fields[i].id, &e->extra_fields[i].size, ZIP_FL_LOCAL);
+ if (e->extra_fields[i].data == NULL)
return -1;
e->extra_fields[i].flags = ZIP_FL_LOCAL;
}
for (; i<e->n_extra_fields; i++) {
e->extra_fields[i].name = e->name;
- if ((e->extra_fields[i].data=zip_file_extra_field_get(za, idx, i-n_local, &e->extra_fields[i].id, &e->extra_fields[i].size, ZIP_FL_CENTRAL)) == NULL)
+ e->extra_fields[i].data=zip_file_extra_field_get(za, idx, (zip_uint16_t)(i-n_local), &e->extra_fields[i].id, &e->extra_fields[i].size, ZIP_FL_CENTRAL);
+ if (e->extra_fields[i].data == NULL)
return -1;
e->extra_fields[i].flags = ZIP_FL_CENTRAL;
}