diff options
Diffstat (limited to 'source')
74 files changed, 352 insertions, 334 deletions
diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c index 2cbe3a80..309acd71 100644 --- a/source/cbz/mucbz.c +++ b/source/cbz/mucbz.c @@ -190,7 +190,7 @@ static int cbz_lookup_metadata(fz_context *ctx, cbz_document *doc, const char *key, char *buf, int size) { if (!strcmp(key, "format")) - return fz_strlcpy(buf, "CBZ", size); + return (int)fz_strlcpy(buf, "CBZ", size); return -1; } diff --git a/source/cbz/muimg.c b/source/cbz/muimg.c index 41831cdf..d0087fa7 100644 --- a/source/cbz/muimg.c +++ b/source/cbz/muimg.c @@ -85,7 +85,7 @@ static int img_lookup_metadata(fz_context *ctx, img_document *doc, const char *key, char *buf, int size) { if (!strcmp(key, "format")) - return fz_strlcpy(buf, "Image", size); + return (int)fz_strlcpy(buf, "Image", size); return -1; } diff --git a/source/cbz/mutiff.c b/source/cbz/mutiff.c index 57e90ea3..ad859987 100644 --- a/source/cbz/mutiff.c +++ b/source/cbz/mutiff.c @@ -103,7 +103,7 @@ static int tiff_lookup_metadata(fz_context *ctx, tiff_document *doc, const char *key, char *buf, int size) { if (!strcmp(key, "format")) - return fz_strlcpy(buf, "TIFF", size); + return (int)fz_strlcpy(buf, "TIFF", size); return -1; } diff --git a/source/fitz/bidi-impl.h b/source/fitz/bidi-impl.h index e9a5b3b4..08749879 100644 --- a/source/fitz/bidi-impl.h +++ b/source/fitz/bidi-impl.h @@ -72,8 +72,8 @@ enum BIDI_LEVEL_MAX = 125 /* Updated for 6.3.0 */ }; -void fz_bidi_resolve_neutrals(fz_bidi_level baselevel, fz_bidi_chartype *pcls, const fz_bidi_level *plevel, int cch); -void fz_bidi_resolve_implicit(const fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch); -void fz_bidi_resolve_weak(fz_context *ctx, fz_bidi_level baselevel, fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch); -void fz_bidi_resolve_whitespace(fz_bidi_level baselevel, const fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch); -int fz_bidi_resolve_explicit(fz_bidi_level level, fz_bidi_chartype dir, fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch, fz_bidi_level nNest); +void fz_bidi_resolve_neutrals(fz_bidi_level baselevel, fz_bidi_chartype *pcls, const fz_bidi_level *plevel, size_t cch); +void fz_bidi_resolve_implicit(const fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch); +void fz_bidi_resolve_weak(fz_context *ctx, fz_bidi_level baselevel, fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch); +void fz_bidi_resolve_whitespace(fz_bidi_level baselevel, const fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch); +size_t fz_bidi_resolve_explicit(fz_bidi_level level, fz_bidi_chartype dir, fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch, fz_bidi_level nNest); diff --git a/source/fitz/bidi-std.c b/source/fitz/bidi-std.c index 7315a88d..1f88bdee 100644 --- a/source/fitz/bidi-std.c +++ b/source/fitz/bidi-std.c @@ -323,24 +323,24 @@ void reverse(uint32_t *psz, int cch) // Set a run of cval values at locations all prior to, but not including // iStart, to the new value nval. static -void set_deferred_run(fz_bidi_chartype *pval, int cval, int iStart, fz_bidi_chartype nval) +void set_deferred_run(fz_bidi_chartype *pval, size_t cval, size_t iStart, fz_bidi_chartype nval) { - int i; + size_t i; - for (i = iStart - 1; i >= iStart - cval; i--) + for (i = iStart; i > iStart - cval; ) { - pval[i] = nval; + pval[--i] = nval; } } static -void set_deferred_level_run(fz_bidi_level *pval, int cval, int iStart, fz_bidi_level nval) +void set_deferred_level_run(fz_bidi_level *pval, size_t cval, size_t iStart, fz_bidi_level nval) { - int i; + size_t i; - for (i = iStart - 1; i >= iStart - cval; i--) + for (i = iStart; i > iStart - cval; ) { - pval[i] = nval; + pval[--i] = nval; } } @@ -451,10 +451,10 @@ static fz_bidi_chartype embedding_direction(fz_bidi_chartype level) the outermost call. The nesting counter counts the recursion depth and not the embedding level. ------------------------------------------------------------------------*/ -int fz_bidi_resolve_explicit(fz_bidi_level level, fz_bidi_chartype dir, fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch, +size_t fz_bidi_resolve_explicit(fz_bidi_level level, fz_bidi_chartype dir, fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch, fz_bidi_level n_nest) { - int ich; + size_t ich; // always called with a valid nesting level // nesting levels are != embedding levels @@ -704,23 +704,23 @@ fz_bidi_chartype get_resolved_type(fz_bidi_action action) Note: On input only these directional classes are expected AL, HL, R, L, ON, BDI_BN, NSM, AN, EN, ES, ET, CS, ------------------------------------------------------------------------*/ -void fz_bidi_resolve_weak(fz_context *ctx, fz_bidi_level baselevel, fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch) +void fz_bidi_resolve_weak(fz_context *ctx, fz_bidi_level baselevel, fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch) { int state = odd(baselevel) ? xr : xl; fz_bidi_chartype cls; - int ich; + size_t ich; fz_bidi_action action; fz_bidi_chartype cls_run; fz_bidi_chartype cls_new; fz_bidi_level level = baselevel; - int cch_run = 0; + size_t cch_run = 0; for (ich = 0; ich < cch; ich++) { if (pcls[ich] > BDI_BN) { - fz_warn(ctx, "error: pcls[%d] > BN (%d)\n", ich, pcls[ich]); + fz_warn(ctx, "error: pcls[" FMT_zu "] > BN (%d)\n", ich, pcls[ich]); } // ignore boundary neutrals @@ -897,15 +897,15 @@ const int state_neutrals[][5] = W8 resolves a number of ENs to L ------------------------------------------------------------------------*/ -void fz_bidi_resolve_neutrals(fz_bidi_level baselevel, fz_bidi_chartype *pcls, const fz_bidi_level *plevel, int cch) +void fz_bidi_resolve_neutrals(fz_bidi_level baselevel, fz_bidi_chartype *pcls, const fz_bidi_level *plevel, size_t cch) { // the state at the start of text depends on the base level int state = odd(baselevel) ? r : l; fz_bidi_chartype cls; - int ich; + size_t ich; fz_bidi_chartype cls_run; - int cch_run = 0; + size_t cch_run = 0; fz_bidi_level level = baselevel; for (ich = 0; ich < cch; ich++) @@ -985,9 +985,9 @@ const fz_bidi_level add_level[][4] = }; -void fz_bidi_resolve_implicit(const fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch) +void fz_bidi_resolve_implicit(const fz_bidi_chartype *pcls, fz_bidi_level *plevel, size_t cch) { - int ich; + size_t ich; for (ich = 0; ich < cch; ich++) { @@ -1058,11 +1058,11 @@ static int resolve_lines(uint32_t *psz_input, int *pbrk, int cch) would have to be adjusted. ------------------------------------------------------------------------*/ void fz_bidi_resolve_whitespace(fz_bidi_level baselevel, const fz_bidi_chartype *pcls, fz_bidi_level *plevel, - int cch) + size_t cch) { - int cchrun = 0; + size_t cchrun = 0; fz_bidi_level oldlevel = baselevel; - int ich; + size_t ich; for (ich = 0; ich < cch; ich++) { diff --git a/source/fitz/bidi.c b/source/fitz/bidi.c index 7d3ca3a2..e05347b7 100644 --- a/source/fitz/bidi.c +++ b/source/fitz/bidi.c @@ -219,10 +219,10 @@ split_at_script(const uint32_t *fragment, static void classify_characters(const uint32_t *text, fz_bidi_chartype *types, - int len, + size_t len, fz_bidi_flags flags) { - int i; + size_t i; if ((flags & BIDI_CLASSIFY_WHITE_SPACE)!=0) { @@ -264,9 +264,9 @@ classify_characters(const uint32_t *text, * Implements rule P2 of the Unicode Bidi Algorithm. * Note: Ignores explicit embeddings */ -static fz_bidi_level base_level_from_text(fz_bidi_chartype *types, int len) +static fz_bidi_level base_level_from_text(fz_bidi_chartype *types, size_t len) { - int i; + size_t i; for (i = 0; i < len; i++) { diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c index 4cff8715..190088e3 100644 --- a/source/fitz/buffer.c +++ b/source/fitz/buffer.c @@ -1,7 +1,7 @@ #include "mupdf/fitz.h" fz_buffer * -fz_new_buffer(fz_context *ctx, int size) +fz_new_buffer(fz_context *ctx, size_t size) { fz_buffer *b; @@ -26,7 +26,7 @@ fz_new_buffer(fz_context *ctx, int size) } fz_buffer * -fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, int size) +fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, size_t size) { fz_buffer *b; @@ -41,7 +41,7 @@ fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, int size) } fz_buffer * -fz_new_buffer_from_shared_data(fz_context *ctx, const char *data, int size) +fz_new_buffer_from_shared_data(fz_context *ctx, const char *data, size_t size) { fz_buffer *b; @@ -57,7 +57,7 @@ fz_new_buffer_from_shared_data(fz_context *ctx, const char *data, int size) } fz_buffer * -fz_new_buffer_from_base64(fz_context *ctx, const char *data, int size) +fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size) { fz_buffer *buf = fz_new_buffer(ctx, size); const char *end = data + size; @@ -109,7 +109,7 @@ fz_drop_buffer(fz_context *ctx, fz_buffer *buf) } void -fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int size) +fz_resize_buffer(fz_context *ctx, fz_buffer *buf, size_t size) { if (buf->shared) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot resize a buffer with shared storage"); @@ -122,16 +122,16 @@ fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int size) void fz_grow_buffer(fz_context *ctx, fz_buffer *buf) { - int newsize = (buf->cap * 3) / 2; + size_t newsize = (buf->cap * 3) / 2; if (newsize == 0) newsize = 256; fz_resize_buffer(ctx, buf, newsize); } static void -fz_ensure_buffer(fz_context *ctx, fz_buffer *buf, int min) +fz_ensure_buffer(fz_context *ctx, fz_buffer *buf, size_t min) { - int newsize = buf->cap; + size_t newsize = buf->cap; if (newsize < 16) newsize = 16; while (newsize < min) @@ -148,7 +148,7 @@ fz_trim_buffer(fz_context *ctx, fz_buffer *buf) fz_resize_buffer(ctx, buf, buf->len); } -int +size_t fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **datap) { if (datap) @@ -169,7 +169,7 @@ fz_append_buffer(fz_context *ctx, fz_buffer *buf, fz_buffer *extra) buf->len += extra->len; } -void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, int len) +void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, size_t len) { if (buf->len + len > buf->cap) fz_ensure_buffer(ctx, buf, buf->len + len); @@ -277,10 +277,10 @@ void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf) buf->unused_bits = 0; } -int +size_t fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...) { - int ret; + size_t ret; va_list args; va_start(args, fmt); ret = fz_buffer_vprintf(ctx, buffer, fmt, args); @@ -288,11 +288,11 @@ fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...) return ret; } -int +size_t fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list old_args) { - int slack; - int len; + size_t slack; + size_t len; va_list args; slack = buffer->cap - buffer->len; @@ -321,7 +321,7 @@ fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list o void fz_buffer_print_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text) { - int len = 2; + size_t len = 2; const char *s = text; char *d; char c; diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c index 89f16e30..d30f98eb 100644 --- a/source/fitz/colorspace.c +++ b/source/fitz/colorspace.c @@ -291,8 +291,8 @@ static void fast_gray_to_rgb(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 3); - int s_line_inc = src->stride - w * (src->alpha + 1); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 3); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 1); if ((int)w < 0 || h < 0) return; @@ -369,8 +369,8 @@ static void fast_gray_to_cmyk(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 4); - int s_line_inc = src->stride - w * (src->alpha + 1); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 4); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 1); if ((int)w < 0 || h < 0) return; @@ -450,8 +450,8 @@ static void fast_rgb_to_gray(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 1); - int s_line_inc = src->stride - w * (src->alpha + 3); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 1); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 3); if ((int)w < 0 || h < 0) return; @@ -522,8 +522,8 @@ static void fast_bgr_to_gray(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 1); - int s_line_inc = src->stride - w * (src->alpha + 3); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 1); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 3); if ((int)w < 0 || h < 0) return; @@ -594,8 +594,8 @@ static void fast_rgb_to_cmyk(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 4); - int s_line_inc = src->stride - w * (src->alpha + 3); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 4); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 3); if ((int)w < 0 || h < 0) return; @@ -687,8 +687,8 @@ static void fast_bgr_to_cmyk(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 4); - int s_line_inc = src->stride - w * (src->alpha + 3); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 4); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 3); if ((int)w < 0 || h < 0) return; @@ -780,8 +780,8 @@ static void fast_cmyk_to_gray(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 1); - int s_line_inc = src->stride - w * (src->alpha + 4); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 1); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 4); if ((int)w < 0 || h < 0) return; @@ -1187,8 +1187,8 @@ static void fast_cmyk_to_rgb(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 3); - int s_line_inc = src->stride - w * (src->alpha + 4); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 3); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 4); unsigned int C,M,Y,K; unsigned char r,g,b; @@ -1286,8 +1286,8 @@ static void fast_cmyk_to_bgr(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 3); - int s_line_inc = src->stride - w * (src->alpha + 4); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 3); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 4); unsigned int C,M,Y,K; unsigned char r,g,b; @@ -1378,8 +1378,8 @@ static void fast_rgb_to_bgr(fz_pixmap *dst, fz_pixmap *src) unsigned char *d = dst->samples; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * (dst->alpha + 3); - int s_line_inc = src->stride - w * (src->alpha + 3); + ptrdiff_t d_line_inc = dst->stride - w * (dst->alpha + 3); + ptrdiff_t s_line_inc = src->stride - w * (src->alpha + 3); if ((int)w < 0 || h < 0) return; @@ -1454,8 +1454,8 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) int k, i; size_t w = src->w; int h = src->h; - int d_line_inc = dst->stride - w * dst->n; - int s_line_inc = src->stride - w * src->n; + ptrdiff_t d_line_inc = dst->stride - w * dst->n; + ptrdiff_t s_line_inc = src->stride - w * src->n; int da = dst->alpha; int sa = src->alpha; @@ -1641,8 +1641,8 @@ static void fast_copy_alpha(fz_pixmap *dst, fz_pixmap *src) size_t w = src->w; int h = src->h; int n = src->n; - int d_line_inc = dst->stride - w * dst->n; - int s_line_inc = src->stride - w * src->n; + ptrdiff_t d_line_inc = dst->stride - w * dst->n; + ptrdiff_t s_line_inc = src->stride - w * src->n; if ((int)w < 0 || h < 0) return; diff --git a/source/fitz/crypt-aes.c b/source/fitz/crypt-aes.c index f98fb8fd..cc298731 100644 --- a/source/fitz/crypt-aes.c +++ b/source/fitz/crypt-aes.c @@ -475,7 +475,7 @@ void aes_crypt_ecb( aes_context *ctx, */ void aes_crypt_cbc( aes_context *ctx, int mode, - int length, + size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output ) diff --git a/source/fitz/crypt-arc4.c b/source/fitz/crypt-arc4.c index 9c54fbae..6031f1ff 100644 --- a/source/fitz/crypt-arc4.c +++ b/source/fitz/crypt-arc4.c @@ -24,10 +24,10 @@ #include "mupdf/fitz.h" void -fz_arc4_init(fz_arc4 *arc4, const unsigned char *key, unsigned keylen) +fz_arc4_init(fz_arc4 *arc4, const unsigned char *key, size_t keylen) { unsigned int t, u; - unsigned int keyindex; + size_t keyindex; unsigned int stateindex; unsigned char *state; unsigned int counter; @@ -86,9 +86,9 @@ fz_arc4_next(fz_arc4 *arc4) } void -fz_arc4_encrypt(fz_arc4 *arc4, unsigned char *dest, const unsigned char *src, unsigned len) +fz_arc4_encrypt(fz_arc4 *arc4, unsigned char *dest, const unsigned char *src, size_t len) { - unsigned int i; + size_t i; for (i = 0; i < len; i++) { unsigned char x; diff --git a/source/fitz/crypt-md5.c b/source/fitz/crypt-md5.c index 7490c0bc..d2693b05 100644 --- a/source/fitz/crypt-md5.c +++ b/source/fitz/crypt-md5.c @@ -210,12 +210,12 @@ void fz_md5_init(fz_md5 *context) /* MD5 block update operation. Continues an MD5 message-digest operation, * processing another message block, and updating the context. */ -void fz_md5_update(fz_md5 *context, const unsigned char *input, unsigned inlen) +void fz_md5_update(fz_md5 *context, const unsigned char *input, size_t inlen) { - unsigned i, index, partlen; + size_t i, index, partlen; /* Compute number of bytes mod 64 */ - index = (unsigned)((context->count[0] >> 3) & 0x3F); + index = (size_t)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ context->count[0] += (unsigned int) inlen << 3; diff --git a/source/fitz/crypt-sha2.c b/source/fitz/crypt-sha2.c index 329069fb..20f827fe 100644 --- a/source/fitz/crypt-sha2.c +++ b/source/fitz/crypt-sha2.c @@ -142,7 +142,7 @@ void fz_sha256_init(fz_sha256 *context) context->state[7] = 0x5BE0CD19; } -void fz_sha256_update(fz_sha256 *context, const unsigned char *input, unsigned int inlen) +void fz_sha256_update(fz_sha256 *context, const unsigned char *input, size_t inlen) { /* Copy the input data into a properly aligned temporary buffer. * This way we can be called with arbitrarily sized buffers @@ -153,7 +153,7 @@ void fz_sha256_update(fz_sha256 *context, const unsigned char *input, unsigned i const unsigned int copy_start = context->count[0] & 0x3F; unsigned int copy_size = 64 - copy_start; if (copy_size > inlen) - copy_size = inlen; + copy_size = (unsigned int)inlen; memcpy(context->buffer.u8 + copy_start, input, copy_size); @@ -314,7 +314,7 @@ void fz_sha512_init(fz_sha512 *context) context->state[7] = 0x5BE0CD19137E2179ull; } -void fz_sha512_update(fz_sha512 *context, const unsigned char *input, unsigned int inlen) +void fz_sha512_update(fz_sha512 *context, const unsigned char *input, size_t inlen) { /* Copy the input data into a properly aligned temporary buffer. * This way we can be called with arbitrarily sized buffers @@ -325,7 +325,7 @@ void fz_sha512_update(fz_sha512 *context, const unsigned char *input, unsigned i const unsigned int copy_start = context->count[0] & 0x7F; unsigned int copy_size = 128 - copy_start; if (copy_size > inlen) - copy_size = inlen; + copy_size = (unsigned int)inlen; memcpy(context->buffer.u8 + copy_start, input, copy_size); @@ -396,7 +396,7 @@ void fz_sha384_init(fz_sha384 *context) context->state[7] = 0x47B5481DBEFA4FA4ull; } -void fz_sha384_update(fz_sha384 *context, const unsigned char *input, unsigned int inlen) +void fz_sha384_update(fz_sha384 *context, const unsigned char *input, size_t inlen) { fz_sha512_update(context, input, inlen); } diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index 126f715d..bdfa1085 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -13,7 +13,7 @@ const char *fz_draw_options_usage = static int opteq(const char *a, const char *b) { - int n = strlen(b); + size_t n = strlen(b); return !strncmp(a, b, n) && (a[n] == ',' || a[n] == 0); } diff --git a/source/fitz/draw-glyph.c b/source/fitz/draw-glyph.c index 98f9252b..014cc13a 100644 --- a/source/fitz/draw-glyph.c +++ b/source/fitz/draw-glyph.c @@ -33,10 +33,10 @@ struct fz_glyph_cache_entry_s struct fz_glyph_cache_s { int refs; - int total; + size_t total; #ifndef NDEBUG int num_evictions; - int evicted; + ptrdiff_t evicted; #endif fz_glyph_cache_entry *entry[GLYPH_HASH_LEN]; fz_glyph_cache_entry *lru_head; @@ -453,8 +453,8 @@ fz_dump_glyph_cache_stats(fz_context *ctx) { fz_glyph_cache *cache = ctx->glyph_cache; - fprintf(stderr, "Glyph Cache Size: %d\n", cache->total); + fprintf(stderr, "Glyph Cache Size: " FMT_zu "\n", cache->total); #ifndef NDEBUG - fprintf(stderr, "Glyph Cache Evictions: %d (%d bytes)\n", cache->num_evictions, cache->evicted); + fprintf(stderr, "Glyph Cache Evictions: %d (" FMT_zu " bytes)\n", cache->num_evictions, cache->evicted); #endif } diff --git a/source/fitz/draw-unpack.c b/source/fitz/draw-unpack.c index 0211b7e4..d2a0c72e 100644 --- a/source/fitz/draw-unpack.c +++ b/source/fitz/draw-unpack.c @@ -47,7 +47,7 @@ init_get1_tables(void) } void -fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale) +fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, int n, int depth, size_t stride, int scale) { int pad, x, y, k; int w = dst->w; @@ -71,8 +71,8 @@ fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, in for (y = 0; y < dst->h; y++) { - unsigned char *sp = src + (unsigned int)(y * stride); - unsigned char *dp = dst->samples + (unsigned int)(y * dst->stride); + unsigned char *sp = src + (y * stride); + unsigned char *dp = dst->samples + (y * dst->stride); /* Specialized loops */ diff --git a/source/fitz/filter-basic.c b/source/fitz/filter-basic.c index 20bb6619..0211442c 100644 --- a/source/fitz/filter-basic.c +++ b/source/fitz/filter-basic.c @@ -13,16 +13,16 @@ fz_open_copy(fz_context *ctx, fz_stream *chain) struct null_filter { fz_stream *chain; - int remain; + size_t remain; fz_off_t offset; unsigned char buffer[4096]; }; static int -next_null(fz_context *ctx, fz_stream *stm, int max) +next_null(fz_context *ctx, fz_stream *stm, size_t max) { struct null_filter *state = stm->state; - int n; + size_t n; if (state->remain == 0) return EOF; @@ -89,10 +89,10 @@ struct concat_filter }; static int -next_concat(fz_context *ctx, fz_stream *stm, int max) +next_concat(fz_context *ctx, fz_stream *stm, size_t max) { struct concat_filter *state = (struct concat_filter *)stm->state; - int n; + size_t n; while (state->current < state->count) { @@ -207,7 +207,7 @@ static inline int unhex(int a) } static int -next_ahxd(fz_context *ctx, fz_stream *stm, int max) +next_ahxd(fz_context *ctx, fz_stream *stm, size_t max) { fz_ahxd *state = stm->state; unsigned char *p = state->buffer; @@ -305,7 +305,7 @@ struct fz_a85d_s }; static int -next_a85d(fz_context *ctx, fz_stream *stm, int max) +next_a85d(fz_context *ctx, fz_stream *stm, size_t max) { fz_a85d *state = stm->state; unsigned char *p = state->buffer; @@ -449,7 +449,7 @@ struct fz_rld_s }; static int -next_rld(fz_context *ctx, fz_stream *stm, int max) +next_rld(fz_context *ctx, fz_stream *stm, size_t max) { fz_rld *state = stm->state; unsigned char *p = state->buffer; @@ -562,10 +562,10 @@ struct fz_arc4c_s }; static int -next_arc4(fz_context *ctx, fz_stream *stm, int max) +next_arc4(fz_context *ctx, fz_stream *stm, size_t max) { fz_arc4c *state = stm->state; - int n = fz_available(ctx, state->chain, max); + size_t n = fz_available(ctx, state->chain, max); if (n == 0) return EOF; @@ -627,7 +627,7 @@ struct fz_aesd_s }; static int -next_aesd(fz_context *ctx, fz_stream *stm, int max) +next_aesd(fz_context *ctx, fz_stream *stm, size_t max) { fz_aesd *state = stm->state; unsigned char *p = state->buffer; @@ -650,7 +650,7 @@ next_aesd(fz_context *ctx, fz_stream *stm, int max) while (p < ep) { - int n = fz_read(ctx, state->chain, state->bp, 16); + size_t n = fz_read(ctx, state->chain, state->bp, 16); if (n == 0) break; else if (n < 16) diff --git a/source/fitz/filter-dct.c b/source/fitz/filter-dct.c index c18ae79d..fee39f69 100644 --- a/source/fitz/filter-dct.c +++ b/source/fitz/filter-dct.c @@ -140,7 +140,7 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) { while ((size_t)num_bytes > src->bytes_in_buffer) { - num_bytes -= src->bytes_in_buffer; + num_bytes -= (long)src->bytes_in_buffer; (void) src->fill_input_buffer(cinfo); } src->next_input_byte += num_bytes; @@ -149,7 +149,7 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) } static int -next_dctd(fz_context *ctx, fz_stream *stm, int max) +next_dctd(fz_context *ctx, fz_stream *stm, size_t max) { fz_dctd *state = stm->state; j_decompress_ptr cinfo = &state->cinfo; diff --git a/source/fitz/filter-fax.c b/source/fitz/filter-fax.c index 7a4d7485..74297936 100644 --- a/source/fitz/filter-fax.c +++ b/source/fitz/filter-fax.c @@ -539,7 +539,7 @@ dec2d(fz_context *ctx, fz_faxd *fax) } static int -next_faxd(fz_context *ctx, fz_stream *stm, int max) +next_faxd(fz_context *ctx, fz_stream *stm, size_t max) { fz_faxd *fax = stm->state; unsigned char *p = fax->buffer; diff --git a/source/fitz/filter-flate.c b/source/fitz/filter-flate.c index 46ff6970..31519066 100644 --- a/source/fitz/filter-flate.c +++ b/source/fitz/filter-flate.c @@ -22,7 +22,7 @@ static void zfree(void *opaque, void *ptr) } static int -next_flated(fz_context *ctx, fz_stream *stm, int required) +next_flated(fz_context *ctx, fz_stream *stm, size_t required) { fz_flate *state = stm->state; fz_stream *chain = state->chain; @@ -39,7 +39,7 @@ next_flated(fz_context *ctx, fz_stream *stm, int required) while (zp->avail_out > 0) { - zp->avail_in = fz_available(ctx, chain, 1); + zp->avail_in = (uInt)fz_available(ctx, chain, 1); zp->next_in = chain->rp; code = inflate(zp, Z_SYNC_FLUSH); diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c index b90f1d42..0ce72201 100644 --- a/source/fitz/filter-jbig2.c +++ b/source/fitz/filter-jbig2.c @@ -287,7 +287,7 @@ close_jbig2d(fz_context *ctx, void *state_) } static int -next_jbig2d(fz_context *ctx, fz_stream *stm, int len) +next_jbig2d(fz_context *ctx, fz_stream *stm, size_t len) { fz_jbig2d *state = stm->state; unsigned char tmp[4096]; @@ -295,7 +295,8 @@ next_jbig2d(fz_context *ctx, fz_stream *stm, int len) unsigned char *p = buf; unsigned char *ep; unsigned char *s; - int x, w, n; + int x, w; + size_t n; if (len > sizeof(state->buffer)) len = sizeof(state->buffer); diff --git a/source/fitz/filter-leech.c b/source/fitz/filter-leech.c index 90e28565..c8f28b7c 100644 --- a/source/fitz/filter-leech.c +++ b/source/fitz/filter-leech.c @@ -11,11 +11,11 @@ struct fz_leech_s }; static int -next_leech(fz_context *ctx, fz_stream *stm, int max) +next_leech(fz_context *ctx, fz_stream *stm, size_t max) { fz_leech *state = stm->state; fz_buffer *buffer = state->buffer; - int n = fz_available(ctx, state->chain, max); + size_t n = fz_available(ctx, state->chain, max); if (n > max) n = max; diff --git a/source/fitz/filter-lzw.c b/source/fitz/filter-lzw.c index cb977772..d7b97407 100644 --- a/source/fitz/filter-lzw.c +++ b/source/fitz/filter-lzw.c @@ -49,7 +49,7 @@ struct fz_lzwd_s }; static int -next_lzwd(fz_context *ctx, fz_stream *stm, int len) +next_lzwd(fz_context *ctx, fz_stream *stm, size_t len) { fz_lzwd *lzw = stm->state; lzw_code *table = lzw->table; diff --git a/source/fitz/filter-predict.c b/source/fitz/filter-predict.c index 3136c651..02475c41 100644 --- a/source/fitz/filter-predict.c +++ b/source/fitz/filter-predict.c @@ -59,7 +59,7 @@ static inline int paeth(int a, int b, int c) } static void -fz_predict_tiff(fz_predict *state, unsigned char *out, unsigned char *in, int len) +fz_predict_tiff(fz_predict *state, unsigned char *out, unsigned char *in) { int left[FZ_MAX_COLORS]; int i, k; @@ -95,14 +95,14 @@ fz_predict_tiff(fz_predict *state, unsigned char *out, unsigned char *in, int le } static void -fz_predict_png(fz_predict *state, unsigned char *out, unsigned char *in, int len, int predictor) +fz_predict_png(fz_predict *state, unsigned char *out, unsigned char *in, size_t len, int predictor) { int bpp = state->bpp; - int i; + size_t i; unsigned char *ref = state->ref; - if (bpp > len) - bpp = len; + if ((size_t)bpp > len) + bpp = (int)len; switch (predictor) { @@ -157,14 +157,14 @@ fz_predict_png(fz_predict *state, unsigned char *out, unsigned char *in, int len } static int -next_predict(fz_context *ctx, fz_stream *stm, int len) +next_predict(fz_context *ctx, fz_stream *stm, size_t len) { fz_predict *state = stm->state; unsigned char *buf = state->buffer; unsigned char *p = buf; unsigned char *ep; int ispng = state->predictor >= 10; - int n; + size_t n; if (len >= sizeof(state->buffer)) len = sizeof(state->buffer); @@ -182,7 +182,7 @@ next_predict(fz_context *ctx, fz_stream *stm, int len) if (state->predictor == 1) memcpy(state->out, state->in, n); else if (state->predictor == 2) - fz_predict_tiff(state, state->out, state->in, n); + fz_predict_tiff(state, state->out, state->in); else { fz_predict_png(state, state->out, state->in + 1, n - 1, state->in[0]); diff --git a/source/fitz/filter-sgi.c b/source/fitz/filter-sgi.c index c0fd9a74..ceb2a548 100644 --- a/source/fitz/filter-sgi.c +++ b/source/fitz/filter-sgi.c @@ -214,7 +214,7 @@ sgilog16val(fz_context *ctx, uint16_t v) } static int -next_sgilog16(fz_context *ctx, fz_stream *stm, int max) +next_sgilog16(fz_context *ctx, fz_stream *stm, size_t max) { fz_sgilog16 *state = stm->state; uint16_t *p; @@ -434,7 +434,7 @@ sgilog24val(fz_context *ctx, fz_stream *chain, uint8_t *rgb) } static int -next_sgilog24(fz_context *ctx, fz_stream *stm, int max) +next_sgilog24(fz_context *ctx, fz_stream *stm, size_t max) { fz_sgilog24 *state = stm->state; uint8_t *p; @@ -557,7 +557,7 @@ sgilog32val(fz_context *ctx, uint32_t p, uint8_t *rgb) } static int -next_sgilog32(fz_context *ctx, fz_stream *stm, int max) +next_sgilog32(fz_context *ctx, fz_stream *stm, size_t max) { fz_sgilog32 *state = stm->state; uint32_t *p; diff --git a/source/fitz/font.c b/source/fitz/font.c index 6cc80d0e..cebccf03 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -437,7 +437,7 @@ fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, in fz_keep_freetype(ctx); fz_lock(ctx, FZ_LOCK_FREETYPE); - fterr = FT_New_Memory_Face(ctx->font->ftlib, buffer->data, buffer->len, index, &face); + fterr = FT_New_Memory_Face(ctx->font->ftlib, buffer->data, (FT_Long)buffer->len, index, &face); fz_unlock(ctx, FZ_LOCK_FREETYPE); if (fterr) { diff --git a/source/fitz/image.c b/source/fitz/image.c index 59d09bf1..6f840c38 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -169,7 +169,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_compressed_image { fz_image *image = &cimg->super; fz_pixmap *tile = NULL; - int stride, len, i; + size_t stride, len, i; unsigned char *samples = NULL; int f = 1<<l2factor; int w = image->w; @@ -251,16 +251,16 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_compressed_image int hh; unsigned char *s = samples; int stream_w = (image->w + f - 1)>>l2factor; - int stream_stride = (stream_w * image->n * image->bpc + 7) / 8; + size_t stream_stride = (stream_w * image->n * image->bpc + 7) / 8; int l_margin = subarea->x0 >> l2factor; int t_margin = subarea->y0 >> l2factor; int r_margin = (image->w + f - 1 - subarea->x1) >> l2factor; int b_margin = (image->h + f - 1 - subarea->y1) >> l2factor; int l_skip = (l_margin * image->n * image->bpc)/8; int r_skip = (r_margin * image->n * image->bpc + 7)/8; - int t_skip = t_margin * stream_stride + l_skip; - int b_skip = b_margin * stream_stride + r_skip; - int l = fz_skip(ctx, stm, t_skip); + size_t t_skip = t_margin * stream_stride + l_skip; + size_t b_skip = b_margin * stream_stride + r_skip; + size_t l = fz_skip(ctx, stm, t_skip); len = 0; if (l == t_skip) { @@ -275,7 +275,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_compressed_image if (--hh == 0) break; l = fz_skip(ctx, stm, r_skip + l_skip); - if (l < r_skip + l_skip) + if (l < (size_t)(r_skip + l_skip)) break; } while (1); @@ -864,7 +864,7 @@ void fz_set_pixmap_image_tile(fz_context *ctx, fz_pixmap_image *image, fz_pixmap } fz_image * -fz_new_image_from_data(fz_context *ctx, unsigned char *data, int len) +fz_new_image_from_data(fz_context *ctx, unsigned char *data, size_t len) { fz_buffer *buffer = NULL; fz_image *image; @@ -897,7 +897,7 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer) fz_compressed_buffer *bc = NULL; int w, h, xres, yres; fz_colorspace *cspace = NULL; - int len = buffer->len; + size_t len = buffer->len; unsigned char *buf = buffer->data; fz_image *image; diff --git a/source/fitz/load-bmp.c b/source/fitz/load-bmp.c index 5f23e4fe..5e630b5a 100644 --- a/source/fitz/load-bmp.c +++ b/source/fitz/load-bmp.c @@ -847,7 +847,7 @@ bmp_read_bitmap(fz_context *ctx, struct info *info, unsigned char *p, unsigned c } static fz_pixmap * -bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total, int only_metadata) +bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t total, int only_metadata) { unsigned char *begin = p; unsigned char *end = p + total; @@ -857,7 +857,7 @@ bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total, p = bmp_read_file_header(ctx, info, p, end); - info->filesize = fz_mini(info->filesize, total); + info->filesize = fz_mini(info->filesize, (int)total); if (end - p < 4) fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in bitmap core header in bmp image"); @@ -936,7 +936,7 @@ bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total, } fz_pixmap * -fz_load_bmp(fz_context *ctx, unsigned char *p, int total) +fz_load_bmp(fz_context *ctx, unsigned char *p, size_t total) { struct info bmp; fz_pixmap *image; @@ -949,7 +949,7 @@ fz_load_bmp(fz_context *ctx, unsigned char *p, int total) } void -fz_load_bmp_info(fz_context *ctx, unsigned char *p, int total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) +fz_load_bmp_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { struct info bmp; diff --git a/source/fitz/load-gif.c b/source/fitz/load-gif.c index 06f353f3..053a4493 100644 --- a/source/fitz/load-gif.c +++ b/source/fitz/load-gif.c @@ -385,7 +385,7 @@ gif_mask_transparency(fz_context *ctx, fz_pixmap *image, struct info *info) } static fz_pixmap * -gif_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total, int only_metadata) +gif_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t total, int only_metadata) { fz_pixmap *pix; unsigned char *end = p + total; @@ -514,7 +514,7 @@ gif_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total, } fz_pixmap * -fz_load_gif(fz_context *ctx, unsigned char *p, int total) +fz_load_gif(fz_context *ctx, unsigned char *p, size_t total) { fz_pixmap *image; struct info gif; @@ -527,7 +527,7 @@ fz_load_gif(fz_context *ctx, unsigned char *p, int total) } void -fz_load_gif_info(fz_context *ctx, unsigned char *p, int total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) +fz_load_gif_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { struct info gif; diff --git a/source/fitz/load-jpeg.c b/source/fitz/load-jpeg.c index 1a155191..40fcef51 100644 --- a/source/fitz/load-jpeg.c +++ b/source/fitz/load-jpeg.c @@ -215,7 +215,7 @@ static int extract_app13_resolution(jpeg_saved_marker_ptr marker, int *xres, int } fz_pixmap * -fz_load_jpeg(fz_context *ctx, unsigned char *rbuf, int rlen) +fz_load_jpeg(fz_context *ctx, unsigned char *rbuf, size_t rlen) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr err; @@ -329,7 +329,7 @@ fz_load_jpeg(fz_context *ctx, unsigned char *rbuf, int rlen) } void -fz_load_jpeg_info(fz_context *ctx, unsigned char *rbuf, int rlen, int *xp, int *yp, int *xresp, int *yresp, fz_colorspace **cspacep) +fz_load_jpeg_info(fz_context *ctx, unsigned char *rbuf, size_t rlen, int *xp, int *yp, int *xresp, int *yresp, fz_colorspace **cspacep) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr err; diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c index bcbdaaf3..ab0fb822 100644 --- a/source/fitz/load-jpx.c +++ b/source/fitz/load-jpx.c @@ -30,21 +30,19 @@ static void fz_opj_info_callback(const char *msg, void *client_data) typedef struct stream_block_s { unsigned char *data; - int size; - int pos; + OPJ_SIZE_T size; + OPJ_SIZE_T pos; } stream_block; static OPJ_SIZE_T fz_opj_stream_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) { stream_block *sb = (stream_block *)p_user_data; - int len; + OPJ_SIZE_T len; len = sb->size - sb->pos; - if (len < 0) - len = 0; if (len == 0) return (OPJ_SIZE_T)-1; /* End of file! */ - if ((OPJ_SIZE_T)len > p_nb_bytes) + if (len > p_nb_bytes) len = p_nb_bytes; memcpy(p_buffer, sb->data + sb->pos, len); sb->pos += len; @@ -55,8 +53,8 @@ static OPJ_OFF_T fz_opj_stream_skip(OPJ_OFF_T skip, void * p_user_data) { stream_block *sb = (stream_block *)p_user_data; - if (skip > sb->size - sb->pos) - skip = sb->size - sb->pos; + if (skip > (OPJ_OFF_T)(sb->size - sb->pos)) + skip = (OPJ_OFF_T)(sb->size - sb->pos); sb->pos += skip; return sb->pos; } @@ -65,14 +63,14 @@ static OPJ_BOOL fz_opj_stream_seek(OPJ_OFF_T seek_pos, void * p_user_data) { stream_block *sb = (stream_block *)p_user_data; - if (seek_pos > sb->size) + if (seek_pos > (OPJ_OFF_T)sb->size) return OPJ_FALSE; sb->pos = seek_pos; return OPJ_TRUE; } fz_pixmap * -fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs, int indexed) +fz_load_jpx(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace *defcs, int indexed) { fz_pixmap *img; opj_dparameters_t params; diff --git a/source/fitz/load-jxr.c b/source/fitz/load-jxr.c index 00c0568f..c898ef18 100644 --- a/source/fitz/load-jxr.c +++ b/source/fitz/load-jxr.c @@ -3,13 +3,13 @@ /* TODO: implement JPEG-XR support */ fz_pixmap * -fz_load_jxr(fz_context *ctx, unsigned char *data, int size) +fz_load_jxr(fz_context *ctx, unsigned char *data, size_t size) { fz_throw(ctx, FZ_ERROR_GENERIC, "JPEG-XR codec is not available"); } void -fz_load_jxr_info(fz_context *ctx, unsigned char *data, int size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) +fz_load_jxr_info(fz_context *ctx, unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { fz_throw(ctx, FZ_ERROR_GENERIC, "JPEG-XR codec is not available"); } diff --git a/source/fitz/load-png.c b/source/fitz/load-png.c index 21e6e94e..74af414e 100644 --- a/source/fitz/load-png.c +++ b/source/fitz/load-png.c @@ -367,7 +367,7 @@ png_read_phys(fz_context *ctx, struct info *info, unsigned char *p, unsigned int } static void -png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned int total, int only_metadata) +png_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t total, int only_metadata) { unsigned int passw[7], passh[7], passofs[8]; unsigned int code, size; @@ -554,7 +554,7 @@ png_mask_transparency(struct info *info, fz_pixmap *dst) } fz_pixmap * -fz_load_png(fz_context *ctx, unsigned char *p, int total) +fz_load_png(fz_context *ctx, unsigned char *p, size_t total) { fz_pixmap *image; fz_colorspace *colorspace; @@ -610,7 +610,7 @@ fz_load_png(fz_context *ctx, unsigned char *p, int total) } void -fz_load_png_info(fz_context *ctx, unsigned char *p, int total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) +fz_load_png_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { struct info png; diff --git a/source/fitz/load-tiff.c b/source/fitz/load-tiff.c index 292c1b87..821b64e1 100644 --- a/source/fitz/load-tiff.c +++ b/source/fitz/load-tiff.c @@ -215,7 +215,7 @@ fz_decode_tiff_jpeg(fz_context *ctx, struct tiff *tiff, fz_stream *chain, unsign fz_stream *jpegtables = NULL; int color_transform = -1; /* unset */ if (tiff->jpegtables && (int)tiff->jpegtableslen > 0) - jpegtables = fz_open_memory(ctx, tiff->jpegtables, (int)tiff->jpegtableslen); + jpegtables = fz_open_memory(ctx, tiff->jpegtables, tiff->jpegtableslen); if (tiff->photometric == 2 /* RGB */ || tiff->photometric == 3 /* RGBPal */) color_transform = 0; stm = fz_open_dctd(ctx, chain, color_transform, 0, jpegtables); @@ -764,7 +764,7 @@ fz_swap_tiff_byte_order(unsigned char *buf, int n) } static void -fz_decode_tiff_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, int len) +fz_decode_tiff_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, size_t len) { unsigned version; @@ -868,7 +868,7 @@ fz_decode_tiff_ifd(fz_context *ctx, struct tiff *tiff) } fz_pixmap * -fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, int len, int subimage) +fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, size_t len, int subimage) { fz_pixmap *image; struct tiff tiff = { 0 }; @@ -932,13 +932,13 @@ fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, int len, int subimage } fz_pixmap * -fz_load_tiff(fz_context *ctx, unsigned char *buf, int len) +fz_load_tiff(fz_context *ctx, unsigned char *buf, size_t len) { return fz_load_tiff_subimage(ctx, buf, len, 0); } void -fz_load_tiff_info_subimage(fz_context *ctx, unsigned char *buf, int len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep, int subimage) +fz_load_tiff_info_subimage(fz_context *ctx, unsigned char *buf, size_t len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep, int subimage) { struct tiff tiff = { 0 }; @@ -970,13 +970,13 @@ fz_load_tiff_info_subimage(fz_context *ctx, unsigned char *buf, int len, int *wp } void -fz_load_tiff_info(fz_context *ctx, unsigned char *buf, int len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) +fz_load_tiff_info(fz_context *ctx, unsigned char *buf, size_t len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { fz_load_tiff_info_subimage(ctx, buf, len, wp, hp, xresp, yresp, cspacep, 0); } int -fz_load_tiff_subimage_count(fz_context *ctx, unsigned char *buf, int len) +fz_load_tiff_subimage_count(fz_context *ctx, unsigned char *buf, size_t len) { unsigned offset; unsigned subimage_count = 0; diff --git a/source/fitz/memory.c b/source/fitz/memory.c index 94901d1d..4a498e44 100644 --- a/source/fitz/memory.c +++ b/source/fitz/memory.c @@ -191,7 +191,7 @@ fz_free(fz_context *ctx, void *p) char * fz_strdup(fz_context *ctx, const char *s) { - int len = strlen(s) + 1; + size_t len = strlen(s) + 1; char *ns = fz_malloc(ctx, len); memcpy(ns, s, len); return ns; @@ -200,7 +200,7 @@ fz_strdup(fz_context *ctx, const char *s) char * fz_strdup_no_throw(fz_context *ctx, const char *s) { - int len = strlen(s) + 1; + size_t len = strlen(s) + 1; char *ns = fz_malloc_no_throw(ctx, len); if (ns) memcpy(ns, s, len); diff --git a/source/fitz/output.c b/source/fitz/output.c index 07422955..0fc4fc09 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -7,7 +7,7 @@ struct fz_output_context_s fz_output *err; }; -static void std_write(fz_context *ctx, void *opaque, const void *buffer, int count); +static void std_write(fz_context *ctx, void *opaque, const void *buffer, size_t count); static fz_output fz_stdout_global = { &fz_stdout_global, @@ -83,12 +83,12 @@ fz_stderr(fz_context *ctx) } static void -file_write(fz_context *ctx, void *opaque, const void *buffer, int count) +file_write(fz_context *ctx, void *opaque, const void *buffer, size_t count) { FILE *file = opaque; size_t n; - if (count < 0) + if (count == 0) return; if (count == 1) @@ -100,12 +100,12 @@ file_write(fz_context *ctx, void *opaque, const void *buffer, int count) } n = fwrite(buffer, 1, count, file); - if (n < (size_t)count && ferror(file)) + if (n < count && ferror(file)) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fwrite: %s", strerror(errno)); } static void -std_write(fz_context *ctx, void *opaque, const void *buffer, int count) +std_write(fz_context *ctx, void *opaque, const void *buffer, size_t count) { FILE *f = opaque == &fz_stdout_global ? stdout : opaque == &fz_stderr_global ? stderr : NULL; file_write(ctx, f, buffer, count); @@ -177,7 +177,7 @@ fz_new_output_with_path(fz_context *ctx, const char *filename, int append) } static void -buffer_write(fz_context *ctx, void *opaque, const void *data, int len) +buffer_write(fz_context *ctx, void *opaque, const void *data, size_t len) { fz_buffer *buffer = opaque; fz_write_buffer(ctx, buffer, data, len); @@ -243,7 +243,7 @@ void fz_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list old_args) { char buffer[256], *p = buffer; - int len; + size_t len; va_list args; if (!out) return; diff --git a/source/fitz/printf.c b/source/fitz/printf.c index baa1aa3a..8d6bfb0d 100644 --- a/source/fitz/printf.c +++ b/source/fitz/printf.c @@ -5,8 +5,8 @@ static const char *fz_hex_digits = "0123456789abcdef"; struct fmtbuf { char *p; - int s; - int n; + size_t s; + size_t n; }; static void fmtputc(struct fmtbuf *out, int c) @@ -151,8 +151,8 @@ static void fmtquote(struct fmtbuf *out, const char *s, int sq, int eq) fmtputc(out, eq); } -int -fz_vsnprintf(char *buffer, int space, const char *fmt, va_list args) +size_t +fz_vsnprintf(char *buffer, size_t space, const char *fmt, va_list args) { struct fmtbuf out; fz_matrix *m; @@ -162,7 +162,7 @@ fz_vsnprintf(char *buffer, int space, const char *fmt, va_list args) int64_t i64; double f; char *s; - int length; + size_t length; out.p = buffer; out.s = space; @@ -327,10 +327,10 @@ fz_vsnprintf(char *buffer, int space, const char *fmt, va_list args) return out.n - 1; } -int -fz_snprintf(char *buffer, int space, const char *fmt, ...) +size_t +fz_snprintf(char *buffer, size_t space, const char *fmt, ...) { - int n; + size_t n; va_list ap; va_start(ap, fmt); n = fz_vsnprintf(buffer, space, fmt, ap); diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index c19c5b4b..c7090d33 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -75,7 +75,7 @@ fz_print_stext_sheet(fz_context *ctx, fz_output *out, fz_stext_sheet *sheet) static void send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer) { - int i, len; + size_t i, len; static const char set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; len = buffer->len/3; diff --git a/source/fitz/store.c b/source/fitz/store.c index e29aee2d..862c179c 100644 --- a/source/fitz/store.c +++ b/source/fitz/store.c @@ -120,7 +120,7 @@ evict(fz_context *ctx, fz_item *item) fz_lock(ctx, FZ_LOCK_ALLOC); } -static int +static size_t ensure_space(fz_context *ctx, size_t tofree) { fz_item *item, *prev; @@ -298,7 +298,7 @@ fz_store_item(fz_context *ctx, void *key, void *val_, size_t itemsize, fz_store_ while (size > store->max) { /* ensure_space may drop, then retake the lock */ - int saved = ensure_space(ctx, size - store->max); + size_t saved = ensure_space(ctx, size - store->max); size -= saved; if (saved == 0) { diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c index 1b3ce97d..142df7c2 100644 --- a/source/fitz/stream-open.c +++ b/source/fitz/stream-open.c @@ -73,13 +73,13 @@ typedef struct fz_file_stream_s unsigned char buffer[4096]; } fz_file_stream; -static int next_file(fz_context *ctx, fz_stream *stm, int n) +static int next_file(fz_context *ctx, fz_stream *stm, size_t n) { fz_file_stream *state = stm->state; /* n is only a hint, that we can safely ignore */ n = fread(state->buffer, 1, sizeof(state->buffer), state->file); - if (n < 0) + if (n < sizeof(state->buffer) && ferror(state->file)) fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); stm->rp = state->buffer; stm->wp = state->buffer + n; @@ -168,7 +168,7 @@ fz_open_file_w(fz_context *ctx, const wchar_t *name) /* Memory stream */ -static int next_buffer(fz_context *ctx, fz_stream *stm, int max) +static int next_buffer(fz_context *ctx, fz_stream *stm, size_t max) { return EOF; } @@ -218,7 +218,7 @@ fz_open_buffer(fz_context *ctx, fz_buffer *buf) } fz_stream * -fz_open_memory(fz_context *ctx, unsigned char *data, int len) +fz_open_memory(fz_context *ctx, unsigned char *data, size_t len) { fz_stream *stm; diff --git a/source/fitz/stream-prog.c b/source/fitz/stream-prog.c index 35905e46..042df96f 100644 --- a/source/fitz/stream-prog.c +++ b/source/fitz/stream-prog.c @@ -13,10 +13,10 @@ typedef struct prog_state unsigned char buffer[4096]; } prog_state; -static int next_prog(fz_context *ctx, fz_stream *stm, int len) +static int next_prog(fz_context *ctx, fz_stream *stm, size_t len) { prog_state *ps = (prog_state *)stm->state; - int n; + size_t n; unsigned char *buf = ps->buffer; if (len > sizeof(ps->buffer)) @@ -30,7 +30,7 @@ static int next_prog(fz_context *ctx, fz_stream *stm, int len) av = ps->length; ps->available = av; /* Limit any fetches to be within the data we have */ - if (av < ps->length && len + stm->pos > av) + if (av < ps->length && len + stm->pos > (size_t)av) { len = av - stm->pos; if (len <= 0) @@ -38,8 +38,8 @@ static int next_prog(fz_context *ctx, fz_stream *stm, int len) } } - n = (len > 0 ? fread(buf, 1, (unsigned int)len, ps->file) : 0); - if (n < 0) + n = (len > 0 ? fread(buf, 1, len, ps->file) : 0); + if (n < len && ferror(ps->file)) fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); stm->rp = ps->buffer + stm->pos; stm->wp = ps->buffer + stm->pos + n; diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index 2ace7b1f..b499d68f 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -2,10 +2,10 @@ #define MIN_BOMB (100 << 20) -int -fz_read(fz_context *ctx, fz_stream *stm, unsigned char *buf, int len) +size_t +fz_read(fz_context *ctx, fz_stream *stm, unsigned char *buf, size_t len) { - int count, n; + size_t count, n; count = 0; do @@ -29,9 +29,9 @@ fz_read(fz_context *ctx, fz_stream *stm, unsigned char *buf, int len) static unsigned char skip_buf[4096]; -int fz_skip(fz_context *ctx, fz_stream *stm, int len) +size_t fz_skip(fz_context *ctx, fz_stream *stm, size_t len) { - int count, l, total = 0; + size_t count, l, total = 0; while (len) { @@ -48,16 +48,16 @@ int fz_skip(fz_context *ctx, fz_stream *stm, int len) } fz_buffer * -fz_read_all(fz_context *ctx, fz_stream *stm, int initial) +fz_read_all(fz_context *ctx, fz_stream *stm, size_t initial) { return fz_read_best(ctx, stm, initial, NULL); } fz_buffer * -fz_read_best(fz_context *ctx, fz_stream *stm, int initial, int *truncated) +fz_read_best(fz_context *ctx, fz_stream *stm, size_t initial, int *truncated) { fz_buffer *buf = NULL; - int n; + size_t n; fz_var(buf); @@ -110,7 +110,7 @@ fz_read_best(fz_context *ctx, fz_stream *stm, int initial, int *truncated) } char * -fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, int n) +fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, size_t n) { char *s = mem; int c = EOF; diff --git a/source/fitz/string.c b/source/fitz/string.c index de9ee80f..2eb67d4f 100644 --- a/source/fitz/string.c +++ b/source/fitz/string.c @@ -30,12 +30,12 @@ fz_strsep(char **stringp, const char *delim) return ret; } -int -fz_strlcpy(char *dst, const char *src, int siz) +size_t +fz_strlcpy(char *dst, const char *src, size_t siz) { register char *d = dst; register const char *s = src; - register int n = siz; + register size_t n = siz; /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { @@ -56,13 +56,13 @@ fz_strlcpy(char *dst, const char *src, int siz) return(s - src - 1); /* count does not include NUL */ } -int -fz_strlcat(char *dst, const char *src, int siz) +size_t +fz_strlcat(char *dst, const char *src, size_t siz) { register char *d = dst; register const char *s = src; - register int n = siz; - int dlen; + register size_t n = siz; + size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ while (*d != '\0' && n-- != 0) @@ -85,9 +85,9 @@ fz_strlcat(char *dst, const char *src, int siz) } void -fz_dirname(char *dir, const char *path, int n) +fz_dirname(char *dir, const char *path, size_t n) { - int i; + size_t i; if (!path || !path[0]) { @@ -143,7 +143,7 @@ fz_urldecode(char *url) } void -fz_format_output_path(fz_context *ctx, char *path, int size, const char *fmt, int page) +fz_format_output_path(fz_context *ctx, char *path, size_t size, const char *fmt, int page) { const char *s, *p; char num[40]; diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index acc2c5bc..9a61fbb0 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -678,7 +678,7 @@ svg_dev_ignore_text(fz_context *ctx, fz_device *dev, const fz_text *text, const static void send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer) { - int i, len; + size_t i, len; static const char set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; len = buffer->len/3; diff --git a/source/fitz/tempfile.c b/source/fitz/tempfile.c index 77c7c04a..fd7d0f5f 100644 --- a/source/fitz/tempfile.c +++ b/source/fitz/tempfile.c @@ -23,7 +23,7 @@ char *fz_tempfilename(fz_context *ctx, const char *base, const char *hint) #ifdef USE_HINT_FOR_DIR char *hintpath; - int hintlen; + size_t hintlen; hintlen = strlen(hint); hintpath = fz_malloc(ctx, 1 + hintlen); diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c index 21cfa7a5..929c1d5a 100644 --- a/source/fitz/unzip.c +++ b/source/fitz/unzip.c @@ -214,24 +214,26 @@ static void read_zip_dir(fz_context *ctx, fz_archive *zip) { fz_stream *file = zip->file; unsigned char buf[512]; - int size, back, maxback; - int i, n; + size_t size, back, maxback; + size_t i, n; fz_seek(ctx, file, 0, SEEK_END); size = fz_tell(ctx, file); - maxback = fz_mini(size, 0xFFFF + sizeof buf); - back = fz_mini(maxback, sizeof buf); + maxback = fz_minz(size, 0xFFFF + sizeof buf); + back = fz_minz(maxback, sizeof buf); while (back < maxback) { fz_seek(ctx, file, size - back, 0); n = fz_read(ctx, file, buf, sizeof buf); + if (n < 4) + break; for (i = n - 4; i > 0; i--) { if (!memcmp(buf + i, "PK\5\6", 4)) { - read_zip_dir_imp(ctx, zip, size - back + i); + read_zip_dir_imp(ctx, zip, (int)(size - back + i)); return; } } diff --git a/source/fitz/writer.c b/source/fitz/writer.c index 927ddffe..5c82b1d7 100644 --- a/source/fitz/writer.c +++ b/source/fitz/writer.c @@ -34,7 +34,7 @@ int fz_has_option(fz_context *ctx, const char *opts, const char *key, const char **val) { const char *straw; - int n = strlen(key); + size_t n = strlen(key); while ((opts = fz_get_option(ctx, &straw, val, opts))) if (!strncmp(straw, key, n) && (straw[n] == '=' || straw[n] == ',' || straw[n] == 0)) return 1; diff --git a/source/fitz/xml.c b/source/fitz/xml.c index b7804fc4..1621aed2 100644 --- a/source/fitz/xml.c +++ b/source/fitz/xml.c @@ -248,10 +248,10 @@ void fz_detach_xml(fz_xml *node) node->up->down = NULL; } -static int xml_parse_entity(int *c, char *a) +static size_t xml_parse_entity(int *c, char *a) { char *b; - int i; + size_t i; if (a[1] == '#') { if (a[2] == 'x') @@ -284,7 +284,7 @@ static int xml_parse_entity(int *c, char *a) /* We should only be doing this for XHTML, but it shouldn't be a problem. */ for (i = 0; i < nelem(html_entities); ++i) { - unsigned int n = strlen(html_entities[i].ent); + size_t n = strlen(html_entities[i].ent); if (!memcmp(a+1, html_entities[i].ent, n) && a[1+n] == ';') { *c = html_entities[i].ucs; return n + 2; @@ -585,7 +585,7 @@ parse_attribute_value: return "end of data in attribute value"; } -static char *convert_to_utf8(fz_context *doc, unsigned char *s, int n, int *dofree) +static char *convert_to_utf8(fz_context *doc, unsigned char *s, size_t n, int *dofree) { unsigned char *e = s + n; char *dst, *d; @@ -626,7 +626,7 @@ static char *convert_to_utf8(fz_context *doc, unsigned char *s, int n, int *dofr } fz_xml * -fz_parse_xml(fz_context *ctx, unsigned char *s, int n, int preserve_white) +fz_parse_xml(fz_context *ctx, unsigned char *s, size_t n, int preserve_white) { struct parser parser; fz_xml root, *node; diff --git a/source/fitz/zip.c b/source/fitz/zip.c index 285fb635..dd67e5ac 100644 --- a/source/fitz/zip.c +++ b/source/fitz/zip.c @@ -24,7 +24,7 @@ fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buf int sum; sum = crc32(0, NULL, 0); - sum = crc32(sum, buf->data, buf->len); + sum = crc32(sum, buf->data, (uInt)buf->len); fz_write_buffer_int32_le(ctx, zip->central, ZIP_CENTRAL_DIRECTORY_SIG); fz_write_buffer_int16_le(ctx, zip->central, 0); /* version made by: MS-DOS */ @@ -34,9 +34,9 @@ fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buf fz_write_buffer_int16_le(ctx, zip->central, 0); /* TODO: last mod file time */ fz_write_buffer_int16_le(ctx, zip->central, 0); /* TODO: last mod file date */ fz_write_buffer_int32_le(ctx, zip->central, sum); /* crc-32 */ - fz_write_buffer_int32_le(ctx, zip->central, buf->len); /* csize */ - fz_write_buffer_int32_le(ctx, zip->central, buf->len); /* usize */ - fz_write_buffer_int16_le(ctx, zip->central, strlen(name)); /* file name length */ + fz_write_buffer_int32_le(ctx, zip->central, (int)buf->len); /* csize */ + fz_write_buffer_int32_le(ctx, zip->central, (int)buf->len); /* usize */ + fz_write_buffer_int16_le(ctx, zip->central, (int)strlen(name)); /* file name length */ fz_write_buffer_int16_le(ctx, zip->central, 0); /* extra field length */ fz_write_buffer_int16_le(ctx, zip->central, 0); /* file comment length */ fz_write_buffer_int16_le(ctx, zip->central, 0); /* disk number start */ @@ -52,9 +52,9 @@ fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buf fz_write_int16_le(ctx, zip->output, 0); /* TODO: last mod file time */ fz_write_int16_le(ctx, zip->output, 0); /* TODO: last mod file date */ fz_write_int32_le(ctx, zip->output, sum); /* crc-32 */ - fz_write_int32_le(ctx, zip->output, buf->len); /* csize */ - fz_write_int32_le(ctx, zip->output, buf->len); /* usize */ - fz_write_int16_le(ctx, zip->output, strlen(name)); /* file name length */ + fz_write_int32_le(ctx, zip->output, (int)buf->len); /* csize */ + fz_write_int32_le(ctx, zip->output, (int)buf->len); /* usize */ + fz_write_int16_le(ctx, zip->output, (int)strlen(name)); /* file name length */ fz_write_int16_le(ctx, zip->output, 0); /* extra field length */ fz_write(ctx, zip->output, name, strlen(name)); fz_write(ctx, zip->output, buf->data, buf->len); @@ -67,7 +67,7 @@ fz_drop_zip_writer(fz_context *ctx, fz_zip_writer *zip) { fz_try(ctx) { - int offset = fz_tell_output(ctx, zip->output); + fz_off_t offset = fz_tell_output(ctx, zip->output); fz_write(ctx, zip->output, zip->central->data, zip->central->len); @@ -76,8 +76,8 @@ fz_drop_zip_writer(fz_context *ctx, fz_zip_writer *zip) fz_write_int16_le(ctx, zip->output, 0); /* number of disk where central directory starts */ fz_write_int16_le(ctx, zip->output, zip->count); /* entries in central directory in this disk */ fz_write_int16_le(ctx, zip->output, zip->count); /* entries in central directory in total */ - fz_write_int32_le(ctx, zip->output, zip->central->len); /* size of the central directory */ - fz_write_int32_le(ctx, zip->output, offset); /* offset of the central directory */ + fz_write_int32_le(ctx, zip->output, (int)zip->central->len); /* size of the central directory */ + fz_write_int32_le(ctx, zip->output, (int)offset); /* offset of the central directory */ fz_write_int16_le(ctx, zip->output, 5); /* zip file comment length */ fz_write(ctx, zip->output, "MuPDF", 5); diff --git a/source/html/css-apply.c b/source/html/css-apply.c index bf082f0d..62b06288 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -235,7 +235,7 @@ match_att_has_condition(fz_xml *node, const char *att, const char *needle) { const char *haystack = fz_xml_att(node, att); const char *ss; - int n; + size_t n; if (haystack) { /* Try matching whole property first. */ if (!strcmp(haystack, needle)) @@ -1013,8 +1013,8 @@ color_from_value(fz_css_value *value, fz_css_color initial) if (value->type == CSS_HASH) { - int r, g, b, n; - n = strlen(value->data); + int r, g, b; + size_t n = strlen(value->data); if (n == 3) { r = tohex(value->data[0]) * 16 + tohex(value->data[0]); diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 5f67e0d4..408c3345 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -402,11 +402,11 @@ epub_lookup_metadata(fz_context *ctx, fz_document *doc_, const char *key, char * { epub_document *doc = (epub_document*)doc_; if (!strcmp(key, FZ_META_FORMAT)) - return fz_strlcpy(buf, "EPUB", size); + return (int)fz_strlcpy(buf, "EPUB", size); if (!strcmp(key, FZ_META_INFO_TITLE) && doc->dc_title) - return fz_strlcpy(buf, doc->dc_title, size); + return (int)fz_strlcpy(buf, doc->dc_title, size); if (!strcmp(key, FZ_META_INFO_AUTHOR) && doc->dc_creator) - return fz_strlcpy(buf, doc->dc_creator, size); + return (int)fz_strlcpy(buf, doc->dc_creator, size); return -1; } diff --git a/source/html/html-doc.c b/source/html/html-doc.c index a7f48111..94ceddb4 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -107,7 +107,7 @@ int htdoc_lookup_metadata(fz_context *ctx, fz_document *doc_, const char *key, char *buf, int size) { if (!strcmp(key, "format")) - return fz_strlcpy(buf, "XHTML", size); + return (int)fz_strlcpy(buf, "XHTML", size); return -1; } diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 5fc6e321..95d6151a 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -1828,7 +1828,7 @@ fz_draw_html(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_html *box static char *concat_text(fz_context *ctx, fz_xml *root) { fz_xml *node; - int i = 0, n = 1; + size_t i = 0, n = 1; char *s; for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c index c8594be1..4d5d924c 100644 --- a/source/pdf/pdf-annot-edit.c +++ b/source/pdf/pdf-annot-edit.c @@ -414,7 +414,7 @@ void pdf_set_free_text_details(fz_context *ctx, pdf_document *doc, pdf_annot *an fz_try(ctx) { unsigned char *da_str; - int da_len; + size_t da_len; fz_rect bounds; find_free_font_name(ctx, form_fonts, nbuf, sizeof(nbuf)); diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index 04a4bc75..5eb9c56b 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -403,8 +403,8 @@ typedef struct text_splitter_s float y_orig; float x; float x_end; - int text_start; - int text_end; + size_t text_start; + size_t text_end; int max_lines; int retry; } text_splitter; @@ -445,8 +445,8 @@ static int text_splitter_layout(fz_context *ctx, text_splitter *splitter) char *text; float room; float stride; - int count; - int len; + size_t count; + size_t len; float fontsize = splitter->info->da_rec.font_size; splitter->x = splitter->x_end; @@ -594,9 +594,9 @@ static void fzbuf_print_text_end(fz_context *ctx, fz_buffer *fzbuf) fz_buffer_printf(ctx, fzbuf, fmt_EMC); } -static void fzbuf_print_text_word(fz_context *ctx, fz_buffer *fzbuf, float x, float y, char *text, int count) +static void fzbuf_print_text_word(fz_context *ctx, fz_buffer *fzbuf, float x, float y, char *text, size_t count) { - int i; + size_t i; fz_buffer_printf(ctx, fzbuf, fmt_Td, x, y); fz_buffer_printf(ctx, fzbuf, "("); @@ -677,7 +677,7 @@ static fz_buffer *create_text_appearance(fz_context *ctx, pdf_document *doc, con { float x, y; char *word = text+splitter.text_start; - int wordlen = splitter.text_end-splitter.text_start; + size_t wordlen = splitter.text_end-splitter.text_start; text_splitter_move(&splitter, -line, &x, &y); fzbuf_print_text_word(ctx, fztmp, x, y, word, wordlen); @@ -857,7 +857,7 @@ static int get_matrix(fz_context *ctx, pdf_document *doc, pdf_xobject *form, int static char *to_font_encoding(fz_context *ctx, pdf_font_desc *font, char *utf8) { - int i; + size_t i; int needs_converting = 0; /* Temporary partial solution. We are using a slow lookup in the conversion @@ -894,7 +894,7 @@ static char *to_font_encoding(fz_context *ctx, pdf_font_desc *font, char *utf8) /* If found store the cid */ if (i < font->cid_to_ucs_len) - *bufp++ = i; + *bufp++ = (char)i; } else { @@ -1027,7 +1027,7 @@ static void update_marked_content(fz_context *ctx, pdf_document *doc, pdf_xobjec fz_stream *str_outer = NULL; fz_stream *str_inner = NULL; unsigned char *buf; - int len; + size_t len; fz_buffer *newbuf = NULL; pdf_lexbuf_init(ctx, &lbuf, PDF_LEXBUF_SMALL); @@ -1351,7 +1351,7 @@ void pdf_update_listbox_appearance(fz_context *ctx, pdf_document *doc, pdf_obj * for (i = 0; i < n; i++) { fzbuf_print_text_word(ctx, fzbuf, 0.0, i == 0 ? 0 : -fontsize * - lineheight, opts[i], strlen(opts[i])); + lineheight, opts[i], (int)strlen(opts[i])); } fzbuf_print_text_end(ctx, fzbuf); update_marked_content(ctx, doc, form, fzbuf); @@ -1904,7 +1904,7 @@ void pdf_update_ink_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *an } } -static void add_text(fz_context *ctx, font_info *font_rec, fz_text *text, char *str, int str_len, const fz_matrix *tm_) +static void add_text(fz_context *ctx, font_info *font_rec, fz_text *text, char *str, size_t str_len, const fz_matrix *tm_) { fz_font *font = font_rec->font->font; fz_matrix tm = *tm_; @@ -1934,7 +1934,7 @@ static fz_text *layout_text(fz_context *ctx, font_info *font_rec, char *str, flo fz_try(ctx) { - add_text(ctx, font_rec, text, str, strlen(str), &tm); + add_text(ctx, font_rec, text, str, (int)strlen(str), &tm); } fz_catch(ctx) { @@ -1995,7 +1995,7 @@ static fz_text *fit_text(fz_context *ctx, font_info *font_rec, char *str, fz_rec { float dx, dy; char *word = str+splitter.text_start; - int wordlen = splitter.text_end-splitter.text_start; + size_t wordlen = splitter.text_end-splitter.text_start; text_splitter_move(&splitter, -line, &dx, &dy); tm.e += dx; diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c index b6eec346..c3a8f9dd 100644 --- a/source/pdf/pdf-colorspace.c +++ b/source/pdf/pdf-colorspace.c @@ -210,7 +210,7 @@ load_indexed(fz_context *ctx, pdf_document *doc, pdf_obj *array) fz_try(ctx) { file = pdf_open_stream(ctx, doc, pdf_to_num(ctx, lookupobj), pdf_to_gen(ctx, lookupobj)); - i = fz_read(ctx, file, lookup, n); + i = (int)fz_read(ctx, file, lookup, n); if (i < n) memset(lookup+i, 0, n-i); } diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c index bff6510f..d9c34d7f 100644 --- a/source/pdf/pdf-crypt.c +++ b/source/pdf/pdf-crypt.c @@ -353,7 +353,7 @@ static const unsigned char padding[32] = }; static void -pdf_compute_encryption_key(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, int pwlen, unsigned char *key) +pdf_compute_encryption_key(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, size_t pwlen, unsigned char *key) { unsigned char buf[32]; unsigned int p; @@ -422,7 +422,7 @@ pdf_compute_encryption_key(fz_context *ctx, pdf_crypt *crypt, unsigned char *pas */ static void -pdf_compute_encryption_key_r5(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, int pwlen, int ownerkey, unsigned char *validationkey) +pdf_compute_encryption_key_r5(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, size_t pwlen, int ownerkey, unsigned char *validationkey) { unsigned char buffer[128 + 8 + 48]; fz_sha256 sha256; @@ -477,12 +477,12 @@ pdf_compute_encryption_key_r5(fz_context *ctx, pdf_crypt *crypt, unsigned char * */ static void -pdf_compute_hardened_hash_r6(fz_context *ctx, unsigned char *password, int pwlen, unsigned char salt[16], unsigned char *ownerkey, unsigned char hash[32]) +pdf_compute_hardened_hash_r6(fz_context *ctx, unsigned char *password, size_t pwlen, unsigned char salt[16], unsigned char *ownerkey, unsigned char hash[32]) { unsigned char data[(128 + 64 + 48) * 64]; unsigned char block[64]; int block_size = 32; - int data_len = 0; + size_t data_len = 0; int i, j, sum; fz_sha256 sha256; @@ -545,7 +545,7 @@ pdf_compute_hardened_hash_r6(fz_context *ctx, unsigned char *password, int pwlen } static void -pdf_compute_encryption_key_r6(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, int pwlen, int ownerkey, unsigned char *validationkey) +pdf_compute_encryption_key_r6(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, size_t pwlen, int ownerkey, unsigned char *validationkey) { unsigned char hash[32]; unsigned char iv[16]; @@ -575,7 +575,7 @@ pdf_compute_encryption_key_r6(fz_context *ctx, pdf_crypt *crypt, unsigned char * */ static void -pdf_compute_user_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, int pwlen, unsigned char *output) +pdf_compute_user_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, size_t pwlen, unsigned char *output) { if (crypt->r == 2) { @@ -636,7 +636,7 @@ pdf_compute_user_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *pass */ static int -pdf_authenticate_user_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, int pwlen) +pdf_authenticate_user_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *password, size_t pwlen) { unsigned char output[32]; pdf_compute_user_password(ctx, crypt, password, pwlen, output); @@ -655,7 +655,7 @@ pdf_authenticate_user_password(fz_context *ctx, pdf_crypt *crypt, unsigned char */ static int -pdf_authenticate_owner_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *ownerpass, int pwlen) +pdf_authenticate_owner_password(fz_context *ctx, pdf_crypt *crypt, unsigned char *ownerpass, size_t pwlen) { unsigned char pwbuf[32]; unsigned char key[32]; diff --git a/source/pdf/pdf-field.c b/source/pdf/pdf-field.c index 7e91cb1e..046e3428 100644 --- a/source/pdf/pdf-field.c +++ b/source/pdf/pdf-field.c @@ -17,7 +17,7 @@ pdf_obj *pdf_get_inheritable(fz_context *ctx, pdf_document *doc, pdf_obj *obj, p char *pdf_get_string_or_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - int len = 0; + size_t len = 0; char *buf = NULL; fz_buffer *stmbuf = NULL; char *text = NULL; diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 574519fd..eab26139 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -182,7 +182,7 @@ static int ft_cid_to_gid(pdf_font_desc *fontdesc, int cid) return ft_char_index(fontdesc->font->ft_face, cid); } - if (fontdesc->cid_to_gid && cid < fontdesc->cid_to_gid_len && cid >= 0) + if (fontdesc->cid_to_gid && (size_t)cid < fontdesc->cid_to_gid_len && cid >= 0) return fontdesc->cid_to_gid[cid]; return cid; @@ -962,14 +962,15 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi if (pdf_is_indirect(ctx, cidtogidmap)) { fz_buffer *buf; + size_t z; buf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, cidtogidmap), pdf_to_gen(ctx, cidtogidmap)); fontdesc->cid_to_gid_len = (buf->len) / 2; fontdesc->cid_to_gid = fz_malloc_array(ctx, fontdesc->cid_to_gid_len, sizeof(unsigned short)); fontdesc->size += fontdesc->cid_to_gid_len * sizeof(unsigned short); - for (i = 0; i < fontdesc->cid_to_gid_len; i++) - fontdesc->cid_to_gid[i] = (buf->data[i * 2] << 8) + buf->data[i * 2 + 1]; + for (z = 0; z < fontdesc->cid_to_gid_len; z++) + fontdesc->cid_to_gid[z] = (buf->data[z * 2] << 8) + buf->data[z * 2 + 1]; fz_drop_buffer(ctx, buf); } @@ -1338,9 +1339,9 @@ pdf_print_font(fz_context *ctx, fz_output *out, pdf_font_desc *fontdesc) } } -fz_rect *pdf_measure_text(fz_context *ctx, pdf_font_desc *fontdesc, unsigned char *buf, int len, fz_rect *acc) +fz_rect *pdf_measure_text(fz_context *ctx, pdf_font_desc *fontdesc, unsigned char *buf, size_t len, fz_rect *acc) { - int i; + size_t i; int w = 0; for (i = 0; i < len; i++) @@ -1354,10 +1355,10 @@ fz_rect *pdf_measure_text(fz_context *ctx, pdf_font_desc *fontdesc, unsigned cha return acc; } -float pdf_text_stride(fz_context *ctx, pdf_font_desc *fontdesc, float fontsize, unsigned char *buf, int len, float room, int *count) +float pdf_text_stride(fz_context *ctx, pdf_font_desc *fontdesc, float fontsize, unsigned char *buf, size_t len, float room, size_t *count) { pdf_hmtx h; - int i = 0; + size_t i = 0; float x = 0.0; while(i < len) @@ -1398,12 +1399,12 @@ pdf_add_font_file(fz_context *ctx, pdf_document *doc, fz_font *font) fz_try(ctx) { obj = pdf_new_dict(ctx, doc, 3); - pdf_dict_put_drop(ctx, obj, PDF_NAME_Length1, pdf_new_int(ctx, doc, buf->len)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Length1, pdf_new_int(ctx, doc, (int)buf->len)); switch (ft_font_file_kind(font->ft_face)) { case 1: /* TODO: these may not be the correct values, but I doubt it matters */ - pdf_dict_put_drop(ctx, obj, PDF_NAME_Length2, pdf_new_int(ctx, doc, buf->len)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Length2, pdf_new_int(ctx, doc, (int)buf->len)); pdf_dict_put_drop(ctx, obj, PDF_NAME_Length3, pdf_new_int(ctx, doc, 0)); break; case 2: diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c index 928742ad..09b51d24 100644 --- a/source/pdf/pdf-form.c +++ b/source/pdf/pdf-form.c @@ -116,7 +116,7 @@ pdf_obj *pdf_lookup_field(fz_context *ctx, pdf_obj *form, char *name) { namep = dot + 1; dot = strchr(namep, '.'); - len = dot ? dot - namep : strlen(namep); + len = dot ? dot - namep : (int)strlen(namep); dict = find_field(ctx, form, namep, len); if (dot) form = pdf_dict_get(ctx, dict, PDF_NAME_Kids); @@ -1028,7 +1028,7 @@ static char *get_field_name(fz_context *ctx, pdf_document *doc, pdf_obj *field, char *res = NULL; pdf_obj *parent = pdf_dict_get(ctx, field, PDF_NAME_Parent); char *lname = pdf_to_str_buf(ctx, pdf_dict_get(ctx, field, PDF_NAME_T)); - int llen = strlen(lname); + int llen = (int)strlen(lname); /* * If we found a name at this point in the field hierarchy @@ -1127,7 +1127,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field fz_buffer *fzbuf = NULL; char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME_DA)); unsigned char *buf; - int len; + size_t len; pdf_obj *daobj = NULL; memset(&di, 0, sizeof(di)); @@ -1137,12 +1137,12 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field fz_var(daobj); fz_try(ctx) { - int i; + size_t i; pdf_parse_da(ctx, da, &di); di.col_size = pdf_array_len(ctx, col); - len = fz_mini(di.col_size, nelem(di.col)); + len = fz_mini(di.col_size, (int)nelem(di.col)); for (i = 0; i < len; i++) di.col[i] = pdf_to_real(ctx, pdf_array_get(ctx, col, i)); diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index f2e4551f..fcb9f328 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -142,14 +142,19 @@ pdf_new_real(fz_context *ctx, pdf_document *doc, float f) } pdf_obj * -pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, int len) +pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, size_t len) { pdf_obj_string *obj; + unsigned short l = (unsigned short)len; + + if ((size_t)l != len) + fz_throw(ctx, FZ_ERROR_GENERIC, "Overflow in pdf string"); + obj = Memento_label(fz_malloc(ctx, offsetof(pdf_obj_string, buf) + len + 1), "pdf_obj(string)"); obj->super.refs = 1; obj->super.kind = PDF_STRING; obj->super.flags = 0; - obj->len = len; + obj->len = l; memcpy(obj->buf, str, len); obj->buf[len] = '\0'; return &obj->super; diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c index 163848a0..5b37e6a5 100644 --- a/source/pdf/pdf-op-buffer.c +++ b/source/pdf/pdf-op-buffer.c @@ -664,12 +664,13 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img) fz_printf(ctx, out, "ID\n"); if (ahx) { - for (i = 0; i < buf->len; ++i) + size_t z; + for (z = 0; z < buf->len; ++z) { - int c = buf->data[i]; + int c = buf->data[z]; fz_putc(ctx, out, "0123456789abcdef"[(c >> 4) & 0xf]); fz_putc(ctx, out, "0123456789abcdef"[c & 0xf]); - if ((i & 31) == 31) + if ((z & 31) == 31) fz_putc(ctx, out, '\n'); } fz_putc(ctx, out, '>'); diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index 03b45725..ca21508e 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -889,7 +889,7 @@ pdf_show_char(fz_context *ctx, pdf_run_processor *pr, int cid) ucslen = 0; if (fontdesc->to_unicode) ucslen = pdf_lookup_cmap_full(fontdesc->to_unicode, cid, ucsbuf); - if (ucslen == 0 && cid < fontdesc->cid_to_ucs_len) + if (ucslen == 0 && (size_t)cid < fontdesc->cid_to_ucs_len) { ucsbuf[0] = fontdesc->cid_to_ucs[cid]; ucslen = 1; diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c index ddfd5fff..cfedd67b 100644 --- a/source/pdf/pdf-parse.c +++ b/source/pdf/pdf-parse.c @@ -52,10 +52,10 @@ pdf_to_utf8(fz_context *ctx, pdf_document *doc, pdf_obj *src) fz_buffer *stmbuf = NULL; unsigned char *srcptr; char *dstptr, *dst; - int srclen; - int dstlen = 0; + size_t srclen; + size_t dstlen = 0; int ucs; - int i; + size_t i; fz_var(stmbuf); fz_try(ctx) diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c index af886d6d..08b82a3e 100644 --- a/source/pdf/pdf-repair.c +++ b/source/pdf/pdf-repair.c @@ -281,7 +281,9 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) int stm_len; pdf_token tok; int next; - int i, n, c; + int i; + size_t j, n; + int c; pdf_lexbuf *buf = &doc->lexbuf.base; int num_roots = 0; int max_roots = 0; @@ -316,7 +318,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) n = fz_read(ctx, doc->file, (unsigned char *)buf->scratch, fz_mini(buf->size, 1024)); fz_seek(ctx, doc->file, 0, 0); - for (i = 0; i < n - 4; i++) + for (j = 0; j < n - 4; j++) { if (memcmp(&buf->scratch[i], "%PDF", 4) == 0) { diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index b6e37d39..8d0f6f58 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -694,7 +694,7 @@ static void removeduplicateobjs(fz_context *ctx, pdf_document *doc, pdf_write_st fz_try(ctx) { unsigned char *dataa, *datab; - int lena, lenb; + size_t lena, lenb; sa = pdf_load_raw_renumbered_stream(ctx, doc, num, 0, num, 0); sb = pdf_load_raw_renumbered_stream(ctx, doc, other, 0, other, 0); lena = fz_buffer_storage(ctx, sa, &dataa); @@ -1530,14 +1530,14 @@ static inline int isbinary(int c) static int isbinarystream(fz_buffer *buf) { - int i; + size_t i; for (i = 0; i < buf->len; i++) if (isbinary(buf->data[i])) return 1; return 0; } -static fz_buffer *hexbuf(fz_context *ctx, unsigned char *p, int n) +static fz_buffer *hexbuf(fz_context *ctx, unsigned char *p, size_t n) { static const char hex[17] = "0123456789abcdef"; fz_buffer *buf; @@ -1614,15 +1614,19 @@ static void addhexfilter(fz_context *ctx, pdf_document *doc, pdf_obj *dict) } -static fz_buffer *deflatebuf(fz_context *ctx, unsigned char *p, int n) +static fz_buffer *deflatebuf(fz_context *ctx, unsigned char *p, size_t n) { fz_buffer *buf; uLongf csize; int t; + uLong longN = (uLong)n; + + if (n != (size_t)longN) + fz_throw(ctx, FZ_ERROR_GENERIC, "Buffer to large to deflate"); - buf = fz_new_buffer(ctx, compressBound(n)); - csize = buf->cap; - t = compress(buf->data, &csize, p, n); + buf = fz_new_buffer(ctx, compressBound(longN)); + csize = (uLongf)buf->cap; + t = compress(buf->data, &csize, p, longN); if (t != Z_OK) { fz_drop_buffer(ctx, buf); @@ -1661,7 +1665,7 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts addhexfilter(ctx, doc, obj); - newlen = pdf_new_int(ctx, doc, buf->len); + newlen = pdf_new_int(ctx, doc, (int)buf->len); pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); pdf_drop_obj(ctx, newlen); } @@ -1713,7 +1717,7 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *op addhexfilter(ctx, doc, obj); } - newlen = pdf_new_int(ctx, doc, buf->len); + newlen = pdf_new_int(ctx, doc, (int)buf->len); pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); pdf_drop_obj(ctx, newlen); @@ -2436,7 +2440,7 @@ make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_write_state *opts /* Pad, and then do shared object hint table */ fz_write_buffer_pad(ctx, buf); - opts->hints_shared_offset = buf->len; + opts->hints_shared_offset = (int)buf->len; /* Table F.5: */ /* Header Item 1: Object number of the first object in the shared @@ -2513,7 +2517,7 @@ make_hint_stream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { make_page_offset_hints(ctx, doc, opts, buf); pdf_update_stream(ctx, doc, pdf_load_object(ctx, doc, pdf_xref_len(ctx, doc)-1, 0), buf, 0); - opts->hintstream_len = buf->len; + opts->hintstream_len = (int)buf->len; fz_drop_buffer(ctx, buf); } fz_catch(ctx) @@ -2749,7 +2753,7 @@ static void finalise_write_state(fz_context *ctx, pdf_write_state *opts) static int opteq(const char *a, const char *b) { - int n = strlen(b); + size_t n = strlen(b); return !strncmp(a, b, n) && (a[n] == ',' || a[n] == 0); } diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index f6f4c292..0365e7a7 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -556,7 +556,7 @@ static void pdf_read_start_xref(fz_context *ctx, pdf_document *doc) { unsigned char buf[1024]; - int i, n; + size_t i, n; fz_off_t t; fz_seek(ctx, doc->file, 0, SEEK_END); @@ -567,8 +567,11 @@ pdf_read_start_xref(fz_context *ctx, pdf_document *doc) fz_seek(ctx, doc->file, t, SEEK_SET); n = fz_read(ctx, doc->file, buf, sizeof buf); + if (n < 9) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find startxref"); - for (i = n - 9; i >= 0; i--) + i = n - 9; + do { if (memcmp(buf + i, "startxref", 9) == 0) { @@ -586,7 +589,7 @@ pdf_read_start_xref(fz_context *ctx, pdf_document *doc) return; break; } - } + } while (i-- > 0); fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find startxref"); } @@ -766,7 +769,7 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_off_t ofs; int len; char *s; - int n; + size_t n; pdf_token tok; fz_off_t i; int c; @@ -2225,7 +2228,7 @@ pdf_update_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj, fz_buffer *n fz_drop_buffer(ctx, x->stm_buf); x->stm_buf = fz_keep_buffer(ctx, newbuf); - pdf_dict_puts_drop(ctx, obj, "Length", pdf_new_int(ctx, doc, newbuf->len)); + pdf_dict_puts_drop(ctx, obj, "Length", pdf_new_int(ctx, doc, (int)newbuf->len)); if (!compressed) { pdf_dict_dels(ctx, obj, "Filter"); @@ -2237,18 +2240,18 @@ int pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *buf, int size) { if (!strcmp(key, "format")) - return fz_snprintf(buf, size, "PDF %d.%d", doc->version/10, doc->version % 10); + return (int)fz_snprintf(buf, size, "PDF %d.%d", doc->version/10, doc->version % 10); if (!strcmp(key, "encryption")) { if (doc->crypt) - return fz_snprintf(buf, size, "Standard V%d R%d %d-bit %s", + return (int)fz_snprintf(buf, size, "Standard V%d R%d %d-bit %s", pdf_crypt_version(ctx, doc), pdf_crypt_revision(ctx, doc), pdf_crypt_length(ctx, doc), pdf_crypt_method(ctx, doc)); else - return fz_strlcpy(buf, "None", size); + return (int)fz_strlcpy(buf, "None", size); } if (strstr(key, "info:") == key) @@ -2266,7 +2269,7 @@ pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *b return -1; s = pdf_to_utf8(ctx, doc, info); - n = fz_strlcpy(buf, s, size); + n = (int)fz_strlcpy(buf, s, size); fz_free(ctx, s); return n; } diff --git a/source/tools/murun.c b/source/tools/murun.c index 0b36e727..6d14f99f 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -101,7 +101,8 @@ static void jsB_read(js_State *J) const char *filename = js_tostring(J, 1); FILE *f; char *s; - int n, t; + long n; + size_t t; f = fopen(filename, "rb"); if (!f) { @@ -146,7 +147,7 @@ static void jsB_read(js_State *J) static void jsB_readline(js_State *J) { char line[256]; - int n; + size_t n; if (!fgets(line, sizeof line, stdin)) js_error(J, "cannot read line from stdin"); n = strlen(line); @@ -556,7 +557,7 @@ static int ffi_buffer_has(js_State *J, void *buf_, const char *key) fz_buffer *buf = buf_; int idx; if (is_number(key, &idx)) { - if (idx < 0 || idx >= buf->len) + if (idx < 0 || (size_t)idx >= buf->len) js_rangeerror(J, "index out of bounds"); js_pushnumber(J, buf->data[idx]); return 1; @@ -573,7 +574,7 @@ static int ffi_buffer_put(js_State *J, void *buf_, const char *key) fz_buffer *buf = buf_; int idx; if (is_number(key, &idx)) { - if (idx < 0 || idx >= buf->len) + if (idx < 0 || (size_t)idx >= buf->len) js_rangeerror(J, "index out of bounds"); buf->data[idx] = js_tonumber(J, -1); return 1; diff --git a/source/tools/mutool.c b/source/tools/mutool.c index 20f4f957..97c74fae 100644 --- a/source/tools/mutool.c +++ b/source/tools/mutool.c @@ -46,7 +46,7 @@ static struct { static int namematch(const char *end, const char *start, const char *match) { - int len = strlen(match); + size_t len = strlen(match); return ((end-len >= start) && (strncmp(end-len, match, len) == 0)); } diff --git a/source/tools/pdfextract.c b/source/tools/pdfextract.c index 80c25c2b..2a3689c5 100644 --- a/source/tools/pdfextract.c +++ b/source/tools/pdfextract.c @@ -91,7 +91,7 @@ static void savefont(pdf_obj *dict, int num) char *ext = ""; fz_output *out; char *fontname = "font"; - int len; + size_t len; unsigned char *data; obj = pdf_dict_get(ctx, dict, PDF_NAME_FontName); diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c index 9df8e182..fcede5f7 100644 --- a/source/tools/pdfinfo.c +++ b/source/tools/pdfinfo.c @@ -754,7 +754,7 @@ printinfo(fz_context *ctx, globals *glo, char *filename, int show, int page) if (!strncmp(cs, "Device", 6)) { - int len = strlen(cs + 6); + size_t len = strlen(cs + 6); memmove(cs + 3, cs + 6, len + 1); cs[3 + len + 1] = '\0'; } @@ -773,7 +773,7 @@ printinfo(fz_context *ctx, globals *glo, char *filename, int show, int page) if (!strncmp(altcs, "Device", 6)) { - int len = strlen(altcs + 6); + size_t len = strlen(altcs + 6); memmove(altcs + 3, altcs + 6, len + 1); altcs[3 + len + 1] = '\0'; } diff --git a/source/tools/pdfshow.c b/source/tools/pdfshow.c index 988663a4..d56cbcd6 100644 --- a/source/tools/pdfshow.c +++ b/source/tools/pdfshow.c @@ -70,9 +70,9 @@ static void showpagetree(void) fz_printf(ctx, out, "\n"); } -static void showsafe(unsigned char *buf, int n) +static void showsafe(unsigned char *buf, size_t n) { - int i; + size_t i; for (i = 0; i < n; i++) { if (buf[i] == '\r' || buf[i] == '\n') { putchar('\n'); @@ -97,7 +97,7 @@ static void showstream(int num, int gen) { fz_stream *stm; unsigned char buf[2048]; - int n; + size_t n; showcolumn = 0; diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c index 9110c169..de153dc2 100644 --- a/source/xps/xps-glyphs.c +++ b/source/xps/xps-glyphs.c @@ -354,7 +354,7 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, float y = originy; char *us = unicode; char *is = indices; - int un = 0; + size_t un = 0; if (!unicode && !indices) fz_warn(ctx, "glyphs element with neither characters nor indices"); diff --git a/source/xps/xps-util.c b/source/xps/xps-util.c index 5d708eaa..c7def9f4 100644 --- a/source/xps/xps-util.c +++ b/source/xps/xps-util.c @@ -148,7 +148,7 @@ xps_resolve_url(fz_context *ctx, xps_document *doc, char *output, char *base_uri } else { - int len = fz_strlcpy(output, base_uri, output_size); + size_t len = fz_strlcpy(output, base_uri, output_size); if (len == 0 || output[len-1] != '/') fz_strlcat(output, "/", output_size); fz_strlcat(output, path, output_size); diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c index d359213d..b0c4403a 100644 --- a/source/xps/xps-zip.c +++ b/source/xps/xps-zip.c @@ -3,7 +3,7 @@ static void xps_init_document(fz_context *ctx, xps_document *doc); xps_part * -xps_new_part(fz_context *ctx, xps_document *doc, char *name, unsigned char *data, int size) +xps_new_part(fz_context *ctx, xps_document *doc, char *name, unsigned char *data, size_t size) { xps_part *part; @@ -43,7 +43,7 @@ xps_read_part(fz_context *ctx, xps_document *doc, char *partname) fz_buffer *buf, *tmp; char path[2048]; unsigned char *data; - int size; + size_t size; int count; char *name; int seen_last; @@ -224,7 +224,7 @@ static int xps_lookup_metadata(fz_context *ctx, xps_document *doc, const char *key, char *buf, int size) { if (!strcmp(key, "format")) - return fz_strlcpy(buf, "XPS", size); + return (int)fz_strlcpy(buf, "XPS", size); return -1; } |