From 00895d7c9d6a0cd8b86243c62eecdd7a2bdd981b Mon Sep 17 00:00:00 2001 From: Josh MacDonald Date: Tue, 5 Jan 2016 00:12:13 -0800 Subject: -Wformat fixes --- xdelta3/Makefile.am | 6 +-- xdelta3/testing/regtest.cc | 6 +-- xdelta3/xdelta3-blkcache.h | 6 +-- xdelta3/xdelta3-decode.h | 17 +++++---- xdelta3/xdelta3-djw.h | 28 +++++++------- xdelta3/xdelta3-internal.h | 35 ------------------ xdelta3/xdelta3-main.h | 4 +- xdelta3/xdelta3-second.h | 6 +-- xdelta3/xdelta3.c | 92 +++++++++++++++++++++++----------------------- xdelta3/xdelta3.h | 45 ++++++++++++++++------- 10 files changed, 114 insertions(+), 131 deletions(-) (limited to 'xdelta3') diff --git a/xdelta3/Makefile.am b/xdelta3/Makefile.am index 056b200..6e2b8bb 100644 --- a/xdelta3/Makefile.am +++ b/xdelta3/Makefile.am @@ -79,7 +79,7 @@ endif #common_CFLAGS += -O2 # For additional debugging, add -DXD3_DEBUG=1, 2, 3, ... -xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=0 +xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=9 xdelta3_LDADD = -lm xdelta3decode_CFLAGS = \ @@ -95,9 +95,9 @@ xdelta3decode_CFLAGS = \ -DVCDIFF_TOOLS=0 xdelta3regtest_CXXFLAGS = \ - $(CXX_WFLAGS) $(common_CFLAGS) -DNOT_MAIN=1 -DXD3_DEBUG=1 + $(CXX_WFLAGS) $(common_CFLAGS) -DNOT_MAIN=1 -DXD3_DEBUG=9 xdelta3regtest_CFLAGS = \ - $(C_WFLAGS) $(common_CFLAGS) -DNOT_MAIN=1 -DXD3_DEBUG=1 + $(C_WFLAGS) $(common_CFLAGS) -DNOT_MAIN=1 -DXD3_DEBUG=9 xdelta3regtest_LDADD = -lm xdelta3checksum_CXXFLAGS = \ diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index e5895e0..dd2ab8d 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc @@ -102,11 +102,11 @@ public: xoff_t blks = target_iterator.Blocks(); - IF_DEBUG2(XPR(NTR "target in %s: %" Q "u..%" Q "u %" Q "u(%" Q "u) " + IF_DEBUG2(XPR(NTR "target in %s: %" Q "u[%" Z "u] %" Q "u(%" Q "u) " "verified %" Q "u\n", encoding ? "encoding" : "decoding", target_iterator.Offset(), - target_iterator.Offset() + target_block.Size(), + target_block.Size(), target_iterator.Blkno(), blks, verified_bytes)); @@ -816,7 +816,7 @@ void TestSmallStride() { InMemoryEncodeDecode(spec0, spec1, &block, options); Delta delta(block); - IF_DEBUG1(DP(RINT "[stride=%d] changes=%u adds=%" Q "u\n", + IF_DEBUG1(DP(RINT "[stride=%d] changes=%" W "u adds=%" Q "u\n", s, changes, delta.AddedBytes())); double allowance = Constants::BLOCK_SIZE < 8192 || s < 30 ? 3.0 : 1.1; CHECK_GE(allowance * changes, (double)delta.AddedBytes()); diff --git a/xdelta3/xdelta3-blkcache.h b/xdelta3/xdelta3-blkcache.h index 20a2a4a..36a5c90 100644 --- a/xdelta3/xdelta3-blkcache.h +++ b/xdelta3/xdelta3-blkcache.h @@ -312,12 +312,12 @@ main_getblk_lru (xd3_source *source, xoff_t blkno, main_blklru_list_remove (blru); main_blklru_list_push_back (& lru_list, blru); (*blrup) = blru; - IF_DEBUG1 (DP(RINT "[getblk_lru] HIT blkno = %"Z"u lru_size=%d\n", + IF_DEBUG1 (DP(RINT "[getblk_lru] HIT blkno = %"Q"u lru_size=%"W"u\n", blkno, lru_size)); return 0; } } - IF_DEBUG1 (DP(RINT "[getblk_lru] MISS blkno = %"Z"u lru_size=%d\n", + IF_DEBUG1 (DP(RINT "[getblk_lru] MISS blkno = %"Q"u lru_size=%"W"u\n", blkno, lru_size)); } @@ -446,7 +446,7 @@ main_read_seek_source (xd3_stream *stream, sfile->source_position += nread; blru->size = nread; - IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q" size %u\n", + IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q"u size %"W"u\n", skip_blkno, blru->size)); XD3_ASSERT (sfile->source_position <= pos); diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index bce5956..4e33189 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h @@ -162,7 +162,7 @@ xd3_decode_allocate (xd3_stream *stream, uint8_t **buf_ptr, usize_t *buf_alloc) { - IF_DEBUG2 (DP(RINT "[xd3_decode_allocate] size %u alloc %u\n", + IF_DEBUG2 (DP(RINT "[xd3_decode_allocate] size %"W"u alloc %"W"u\n", size, *buf_alloc)); if (*buf_ptr != NULL && *buf_alloc < size) @@ -207,7 +207,7 @@ xd3_decode_section (xd3_stream *stream, /* No allocation/copy needed */ section->buf = stream->next_in; sect_take = section->size; - IF_DEBUG1 (DP(RINT "[xd3_decode_section] zerocopy %u @ %u avail %u\n", + IF_DEBUG1 (DP(RINT "[xd3_decode_section] zerocopy %"W"u @ %"W"u avail %"W"u\n", sect_take, section->pos, stream->avail_in)); } else @@ -232,7 +232,7 @@ xd3_decode_section (xd3_stream *stream, section->buf = section->copied1; } - IF_DEBUG2 (DP(RINT "[xd3_decode_section] take %u @ %u [need %u] avail %u\n", + IF_DEBUG2 (DP(RINT "[xd3_decode_section] take %"W"u @ %"W"u [need %"W"u] avail %"W"u\n", sect_take, section->pos, sect_need, stream->avail_in)); XD3_ASSERT (section->pos + sect_take <= section->alloc1); @@ -250,7 +250,8 @@ xd3_decode_section (xd3_stream *stream, if (section->pos < section->size) { - IF_DEBUG1 (DP(RINT "[xd3_decode_section] further input required %u\n", section->size - section->pos)); + IF_DEBUG1 (DP(RINT "[xd3_decode_section] further input required %"W"u\n", + section->size - section->pos)); stream->msg = "further input required"; return XD3_INPUT; } @@ -772,7 +773,7 @@ xd3_decode_emit (xd3_stream *stream) if (stream->avail_out != stream->dec_tgtlen) { - IF_DEBUG2 (DP(RINT "AVAIL_OUT(%d) != DEC_TGTLEN(%d)\n", + IF_DEBUG2 (DP(RINT "AVAIL_OUT(%"W"u) != DEC_TGTLEN(%"W"u)\n", stream->avail_out, stream->dec_tgtlen)); stream->msg = "wrong window length"; return XD3_INVALID_INPUT; @@ -1009,7 +1010,7 @@ xd3_decode_input (xd3_stream *stream) stream->dec_state = DEC_CPYLEN; - IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q" -----------\n", + IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q"u -----------\n", stream->current_window)); } @@ -1168,8 +1169,8 @@ xd3_decode_input (xd3_stream *stream) IF_DEBUG2(DP(RINT "[decode_cpyoff] %"Q"u " "cpyblkno %"Q"u " - "cpyblkoff %u " - "blksize %u\n", + "cpyblkoff %"W"u " + "blksize %"W"u\n", stream->dec_cpyoff, src->cpyoff_blocks, src->cpyoff_blkoff, diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h index 414702a..a4c7e51 100644 --- a/xdelta3/xdelta3-djw.h +++ b/xdelta3/xdelta3-djw.h @@ -318,7 +318,7 @@ heap_check (usize_t *heap, djw_heapen *ents, usize_t heap_last) /* Heap property: child not less than parent */ XD3_ASSERT (! heap_less (& ents[heap[i]], & ents[heap[i/2]])); - IF_DEBUG2 (DP(RINT "heap[%d] = %u\n", i, ents[heap[i]].freq)); + IF_DEBUG2 (DP(RINT "heap[%"W"u] = %u\n", i, ents[heap[i]].freq)); } } #endif @@ -404,7 +404,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t for (i = 0; i < asize; i += 1) { ents[i+1].freq = freq[i]; - IF_DEBUG2 (DP(RINT "ents[%d] = freq[%d] = %d\n", + IF_DEBUG2 (DP(RINT "ents[%"W"i] = freq[%"W"u] = %d\n", i+1, i, freq[i])); } @@ -483,7 +483,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t } /* clen is 0-origin, unlike ents. */ - IF_DEBUG2 (DP(RINT "clen[%d] = %d\n", i-1, b)); + IF_DEBUG2 (DP(RINT "clen[%"W"u] = %"W"u\n", i-1, b)); clen[i-1] = b; } @@ -493,7 +493,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t { IF_DEBUG2 (if (first_bits != total_bits) { - DP(RINT "code length overflow changed %"Z" bits\n", + DP(RINT "code length overflow changed %"W"u bits\n", total_bits - first_bits); }); return total_bits; @@ -547,7 +547,7 @@ djw_build_codes (usize_t *codes, const uint8_t *clen, usize_t asize, usize_t abs IF_DEBUG2 ({ for (i = 0; i < asize; i += 1) { - DP(RINT "code[%d] = %u\n", i, codes[i]); + DP(RINT "code[%"W"u] = %"W"u\n", i, codes[i]); } }); } @@ -1021,7 +1021,7 @@ xd3_encode_huff (xd3_stream *stream, * testing group behavior, so don't mess things up. */ if (goal == 0 && !cfg->inefficient) { - IF_DEBUG2 (DP(RINT "too many groups (%u), dropping one\n", + IF_DEBUG2 (DP(RINT "too many groups (%"W"u), dropping one\n", groups)); groups -= 1; goto regroup; @@ -1035,8 +1035,8 @@ xd3_encode_huff (xd3_stream *stream, sum += real_freq[sym2++]; } - IF_DEBUG2(DP(RINT "group %u has symbols %u..%u (%u non-zero) " - "(%u/%u = %.3f)\n", + IF_DEBUG2(DP(RINT "group %"W"u has symbols %"W"u..%"W"u (%"W"u non-zero) " + "(%u/%"W"u = %.3f)\n", gp, sym1, sym2, nz, sum, input_bytes, sum / (double)input_bytes);); @@ -1165,21 +1165,21 @@ xd3_encode_huff (xd3_stream *stream, if (evolve_zero[i]) { output_bits -= evolve_clen[gp][i]; } } - IF_DEBUG2 (DP(RINT "evolve_zero reduced %u bits in group %u\n", + IF_DEBUG2 (DP(RINT "evolve_zero reduced %"W"u bits in group %"W"u\n", save_total - output_bits, gp)); } } IF_DEBUG2( - DP(RINT "pass %u total bits: %u group uses: ", niter, output_bits); - for (gp = 0; gp < groups; gp += 1) { DP(RINT "%u ", gcount[gp]); } + DP(RINT "pass %"W"u total bits: %"W"u group uses: ", niter, output_bits); + for (gp = 0; gp < groups; gp += 1) { DP(RINT "%"W"u ", gcount[gp]); } DP(RINT "\n"); ); /* End iteration. */ IF_DEBUG2 (if (niter > 1 && best_bits < output_bits) { - DP(RINT "iteration lost %u bits\n", output_bits - best_bits); }); + DP(RINT "iteration lost %"W"u bits\n", output_bits - best_bits); }); if (niter == 1 || (niter < DJW_MAX_ITER && (best_bits - output_bits) >= DJW_MIN_IMPROVEMENT)) @@ -1194,7 +1194,7 @@ xd3_encode_huff (xd3_stream *stream, goto nosecond; } - IF_DEBUG2 (DP(RINT "djw compression: %u -> %0.3f\n", + IF_DEBUG2 (DP(RINT "djw compression: %"W"u -> %0.3f\n", input_bytes, output_bits / 8.0)); /* Encode: prefix */ @@ -1471,7 +1471,7 @@ djw_decode_symbol (xd3_stream *stream, if (offset <= max_sym) { - IF_DEBUG2 (DP(RINT "(j) %u ", code)); + IF_DEBUG2 (DP(RINT "(j) %"W"u ", code)); *sym = inorder[offset]; return 0; } diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h index e0c561f..ed5ca2a 100644 --- a/xdelta3/xdelta3-internal.h +++ b/xdelta3/xdelta3-internal.h @@ -136,41 +136,6 @@ struct _main_file int seek_failed; /* after seek fails once, try FIFO */ }; -#ifdef _WIN32 -#define vsnprintf_func _vsnprintf -#define snprintf_func _snprintf -#else -#define vsnprintf_func vsnprintf -#define snprintf_func snprintf -#endif -#define short_sprintf(sb,fmt,...) \ - snprintf_func((sb).buf,sizeof((sb).buf),fmt,__VA_ARGS__) - -/* Type used for short snprintf calls. */ -typedef struct { - char buf[48]; -} shortbuf; - -/* Prior to SVN 303 this function was only defined in DJGPP and WIN32 - * environments and other platforms would use the builtin snprintf() - * with an arrangement of macros below. In OS X 10.6, Apple made - * snprintf() a macro, which defeated those macros (since snprintf - * would be evaluated before its argument macros were expanded, - * therefore always define xsnprintf_func. */ -#ifndef PRINTF_ATTRIBUTE -#define PRINTF_ATTRIBUTE(x,y) __attribute__ ((__format__ (__printf__, x, y))) -#endif - -/* Underlying xprintf() */ -int xsnprintf_func (char *str, size_t n, const char *fmt, ...) - PRINTF_ATTRIBUTE(3,4); - -/* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */ -void xprintf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); -#define XPR xprintf -#define NT "xdelta3: " -#define NTR "" - #ifndef UINT32_MAX #define UINT32_MAX 4294967295U #endif diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 69330ca..d1a848a 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h @@ -1084,7 +1084,7 @@ main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg) { int ret = 0; - IF_DEBUG1(DP(RINT "[main] write %u\n bytes", size)); + IF_DEBUG1(DP(RINT "[main] write %"W"u\n bytes", size)); #if XD3_STDIO usize_t result; @@ -1155,7 +1155,7 @@ main_write_output (xd3_stream* stream, main_file *ofile) { int ret; - IF_DEBUG1(DP(RINT "[main] write(%s) %u\n bytes", ofile->filename, stream->avail_out)); + IF_DEBUG1(DP(RINT "[main] write(%s) %"W"u\n bytes", ofile->filename, stream->avail_out)); if (option_no_output) { diff --git a/xdelta3/xdelta3-second.h b/xdelta3/xdelta3-second.h index 899902e..2e3ccd3 100644 --- a/xdelta3/xdelta3-second.h +++ b/xdelta3/xdelta3-second.h @@ -68,7 +68,7 @@ static inline int xd3_decode_bits (xd3_stream *stream, done: - IF_DEBUG2 (DP(RINT "(d) %u ", value)); + IF_DEBUG2 (DP(RINT "(d) %"W"u ", value)); (*valuep) = value; return 0; @@ -238,7 +238,7 @@ static inline int xd3_encode_bits (xd3_stream *stream, } while (mask != 1); - IF_DEBUG2 (DP(RINT "(e) %u ", value)); + IF_DEBUG2 (DP(RINT "(e) %"W"u ", value)); return 0; } @@ -300,7 +300,7 @@ xd3_encode_secondary (xd3_stream *stream, { if (comp_size < orig_size) { - IF_DEBUG1(DP(RINT "[encode_secondary] saved %u bytes: %u -> %u (%0.2f%%)\n", + IF_DEBUG1(DP(RINT "[encode_secondary] saved %"W"u bytes: %"W"u -> %"W"u (%0.2f%%)\n", orig_size - comp_size, orig_size, comp_size, 100.0 * (double) comp_size / (double) orig_size)); } diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index b0c9b30..294a05a 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c @@ -1424,8 +1424,8 @@ xd3_alloc (xd3_stream *stream, if (a != NULL) { IF_DEBUG (stream->alloc_cnt += 1); - IF_DEBUG2 (DP(RINT "[stream %p malloc] size %u ptr %p\n", - stream, elts * size, a)); + IF_DEBUG2 (DP(RINT "[stream %p malloc] size %"W"u ptr %p\n", + (void*)stream, elts * size, a)); } else { @@ -1444,7 +1444,7 @@ xd3_free (xd3_stream *stream, IF_DEBUG (stream->free_cnt += 1); XD3_ASSERT (stream->free_cnt <= stream->alloc_cnt); IF_DEBUG2 (DP(RINT "[stream %p free] %p\n", - stream, ptr)); + (void*)stream, ptr)); stream->free (stream->opaque, ptr); } } @@ -1889,7 +1889,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) } IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q"u onblk " - "%u blksize %u max_blkno %"Q"u\n", blkno, source->onblk, + "%"W"u blksize %"W"u max_blkno %"Q"u\n", blkno, source->onblk, source->blksize, source->max_blkno)); } @@ -1906,7 +1906,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) } else if (!source->eof_known) { - IF_DEBUG1 (DP(RINT "[getblk] eof block has %d bytes; " + IF_DEBUG1 (DP(RINT "[getblk] eof block has %"W"u bytes; " "source length known %"Q"u\n", xd3_bytes_on_srcblk (source, blkno), xd3_source_eof (source))); @@ -1945,7 +1945,7 @@ xd3_set_source (xd3_stream *stream, { src->blksize = xd3_pow2_roundup(src->blksize); xd3_check_pow2 (src->blksize, &shiftby); - IF_DEBUG1 (DP(RINT "raising src_blksz to %u\n", src->blksize)); + IF_DEBUG1 (DP(RINT "raising src_blksz to %"W"u\n", src->blksize)); } src->shiftby = shiftby; @@ -1954,7 +1954,7 @@ xd3_set_source (xd3_stream *stream, if (xd3_check_pow2 (src->max_winsize, NULL) != 0) { src->max_winsize = xd3_xoff_roundup(src->max_winsize); - IF_DEBUG1 (DP(RINT "raising src_maxsize to %u\n", src->blksize)); + IF_DEBUG1 (DP(RINT "raising src_maxsize to %"W"u\n", src->blksize)); } src->max_winsize = xd3_max (src->max_winsize, XD3_ALLOCSIZE); return 0; @@ -1968,7 +1968,7 @@ xd3_set_source_and_size (xd3_stream *stream, if (ret == 0) { stream->src->eof_known = 1; - IF_DEBUG2 (DP(RINT "[set source] size known %"Q"\n", + IF_DEBUG2 (DP(RINT "[set source] size known %"Q"u\n", source_size)); xd3_blksize_div(source_size, stream->src, @@ -2180,7 +2180,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) IF_DEBUG2 ({ static int cnt; - DP(RINT "[iopt copy:%d] pos %"Q"-%"Q" addr %"Q"-%"Q" size %u\n", + DP(RINT "[iopt copy:%d] pos %"Q"u-%"Q"u addr %"Q"u-%"Q"u size %"W"u\n", cnt++, stream->total_in + inst->pos, stream->total_in + inst->pos + inst->size, @@ -2197,7 +2197,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) IF_DEBUG2 ({ static int cnt; - DP(RINT "[iopt run:%d] pos %"Q" size %u\n", cnt++, stream->total_in + inst->pos, inst->size); + DP(RINT "[iopt run:%d] pos %"Q"u size %"W"u\n", cnt++, stream->total_in + inst->pos, inst->size); }); break; } @@ -2211,7 +2211,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) IF_DEBUG2 ({ static int cnt; - DP(RINT "[iopt add:%d] pos %"Q" size %u\n", cnt++, stream->total_in + inst->pos, inst->size); + DP(RINT "[iopt add:%d] pos %"Q"u size %"W"u\n", cnt++, stream->total_in + inst->pos, inst->size); }); break; @@ -2593,11 +2593,11 @@ xd3_emit_single (xd3_stream *stream, xd3_rinst *single, uint8_t code) int has_size = stream->code_table[code].size1 == 0; int ret; - IF_DEBUG2 (DP(RINT "[emit1] %u %s (%u) code %u\n", - single->pos, + IF_DEBUG2 (DP(RINT "[emit1] %"W"u %s (%"W"u) code %u\n", + single->pos, xd3_rtype_to_string ((xd3_rtype) single->type, 0), - single->size, - code)); + single->size, + code)); if ((ret = xd3_emit_byte (stream, & INST_TAIL (stream), code))) { @@ -2631,13 +2631,13 @@ xd3_emit_double (xd3_stream *stream, xd3_rinst *first, return ret; } - IF_DEBUG2 (DP(RINT "[emit2]: %u %s (%u) %s (%u) code %u\n", - first->pos, + IF_DEBUG2 (DP(RINT "[emit2]: %"W"u %s (%"W"u) %s (%"W"u) code %u\n", + first->pos, xd3_rtype_to_string ((xd3_rtype) first->type, 0), - first->size, + first->size, xd3_rtype_to_string ((xd3_rtype) second->type, 0), - second->size, - code)); + second->size, + code)); return 0; } @@ -2869,7 +2869,8 @@ xd3_encode_buffer_leftover (xd3_stream *stream) XD3_ASSERT (stream->buf_avail == 0); XD3_ASSERT (stream->buf_leftavail < stream->winsize); - IF_DEBUG2 (DP(RINT "[leftover] previous %u avail %u\n", stream->buf_leftavail, stream->avail_in)); + IF_DEBUG2 (DP(RINT "[leftover] previous %"W"u avail %"W"u\n", + stream->buf_leftavail, stream->avail_in)); memcpy (stream->buf_in, stream->buf_leftover, stream->buf_leftavail); @@ -2894,12 +2895,12 @@ xd3_encode_buffer_leftover (xd3_stream *stream) else if ((stream->buf_avail < stream->winsize) && !(stream->flags & XD3_FLUSH)) { /* Buffer has space */ - IF_DEBUG2 (DP(RINT "[leftover] emptied %u\n", take)); + IF_DEBUG2 (DP(RINT "[leftover] emptied %"W"u\n", take)); return XD3_INPUT; } /* Use the buffer: */ - IF_DEBUG2 (DP(RINT "[leftover] take %u remaining %u\n", take, stream->buf_leftavail)); + IF_DEBUG2 (DP(RINT "[leftover] take %"W"u remaining %"W"u\n", take, stream->buf_leftavail)); stream->next_in = stream->buf_in; stream->avail_in = stream->buf_avail; stream->buf_avail = 0; @@ -3124,13 +3125,13 @@ xd3_encode_input (xd3_stream *stream) stream->enc_state = ENC_SEARCH; - IF_DEBUG2 (DP(RINT "[WINSTART:%"Q"] input bytes %u offset %"Q"\n", + IF_DEBUG2 (DP(RINT "[WINSTART:%"Q"u] input bytes %"W"u offset %"Q"u\n", stream->current_window, stream->avail_in, stream->total_in)); return XD3_WINSTART; case ENC_SEARCH: - IF_DEBUG2 (DP(RINT "[SEARCH] match_state %d avail_in %u %s\n", + IF_DEBUG2 (DP(RINT "[SEARCH] match_state %d avail_in %"W"u %s\n", stream->match_state, stream->avail_in, stream->src ? "source" : "no source")); @@ -3266,7 +3267,7 @@ xd3_encode_input (xd3_stream *stream) stream->total_in += stream->avail_in; stream->enc_state = ENC_POSTWIN; - IF_DEBUG2 (DP(RINT "[WINFINISH:%"Q"] in=%"Q"\n", + IF_DEBUG2 (DP(RINT "[WINFINISH:%"Q"u] in=%"Q"u\n", stream->current_window, stream->total_in)); return XD3_WINFINISH; @@ -3669,7 +3670,7 @@ xd3_srcwin_setup (xd3_stream *stream) * for the second block. */ src->srclen = xd3_min (src->srclen, xd3_source_eof(src) - src->srcbase); } - IF_DEBUG1 (DP(RINT "[srcwin_setup_constrained] base %"Q"u len %u\n", + IF_DEBUG1 (DP(RINT "[srcwin_setup_constrained] base %"Q"u len %"W"u\n", src->srcbase, src->srclen)); XD3_ASSERT (src->srclen); @@ -3786,8 +3787,8 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) } IF_DEBUG2(DP(RINT - "[match_setup] srcpos %"Q" (tgtpos %"Q") " - "unrestricted maxback %u maxfwd %u\n", + "[match_setup] srcpos %"Q"u (tgtpos %"Q"u) " + "unrestricted maxback %"W"u maxfwd %"W"u\n", srcpos, stream->total_in + stream->input_position, stream->match_maxback, @@ -3823,7 +3824,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) IF_DEBUG2(DP(RINT "[match_setup] srcpos %"Q"u (tgtpos %"Q"u) " - "restricted maxback %u maxfwd %u\n", + "restricted maxback %"W"u maxfwd %"W"u\n", srcpos, stream->total_in + stream->input_position, stream->match_maxback, @@ -3902,7 +3903,7 @@ xd3_source_extend_match (xd3_stream *stream) usize_t tryrem; /* tryrem is the number of matchable bytes */ usize_t matched; - IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"\n", + IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n", stream->match_srcpos)); XD3_ASSERT (src != NULL); @@ -3930,7 +3931,7 @@ xd3_source_extend_match (xd3_stream *stream) { if (ret == XD3_TOOFARBACK) { - IF_DEBUG2(DP(RINT "[maxback] %"Q"u TOOFARBACK: %u INP %"Q"u CKSUM %"Q"u\n", + IF_DEBUG2(DP(RINT "[maxback] %"Q"u TOOFARBACK: %"W"u INP %"Q"u CKSUM %"Q"u\n", tryblk, stream->match_back, stream->total_in + stream->input_position, stream->srcwin_cksum_pos)); @@ -3952,7 +3953,7 @@ xd3_source_extend_match (xd3_stream *stream) tryrem = xd3_min (tryoff, stream->match_maxback - stream->match_back); - IF_DEBUG2(DP(RINT "[maxback] maxback %u trysrc %"Q"/%u tgt %u tryrem %u\n", + IF_DEBUG2(DP(RINT "[maxback] maxback %"W"u trysrc %"Q"u/%"W"u tgt %"W"u tryrem %"W"u\n", stream->match_maxback, tryblk, tryoff, streamoff, tryrem)); /* TODO: This code can be optimized similar to xd3_match_forward() */ @@ -3991,7 +3992,7 @@ xd3_source_extend_match (xd3_stream *stream) { if (ret == XD3_TOOFARBACK) { - IF_DEBUG2(DP(RINT "[maxfwd] %"Q"u TOOFARBACK: %u INP %"Q"u CKSUM %"Q"u\n", + IF_DEBUG2(DP(RINT "[maxfwd] %"Q"u TOOFARBACK: %"W"u INP %"Q"u CKSUM %"Q"u\n", tryblk, stream->match_fwd, stream->total_in + stream->input_position, stream->srcwin_cksum_pos)); @@ -4030,7 +4031,7 @@ xd3_source_extend_match (xd3_stream *stream) donefwd: stream->match_state = MATCH_SEARCHING; - IF_DEBUG2(DP(RINT "[extend match] input %"Q"u srcpos %"Q"u len %u\n", + IF_DEBUG2(DP(RINT "[extend match] input %"Q"u srcpos %"Q"u len %"W"u\n", stream->input_position + stream->total_in, stream->match_srcpos, stream->match_fwd)); @@ -4086,15 +4087,14 @@ xd3_source_extend_match (xd3_stream *stream) IF_DEBUG2 ({ static int x = 0; - DP(RINT "[source match:%d] length %u (%s) [ %u bytes ]\n", + DP(RINT "[source match:%d] length %"W"u (%s)\n", x++, match_length, stream->total_in + target_position, stream->total_in + target_position + match_length, match_position, match_position + match_length, - (stream->total_in + target_position == match_position) ? "same" : "diff", - match_length); + (stream->total_in + target_position == match_position) ? "same" : "diff"); }); if ((ret = xd3_found_match (stream, @@ -4192,7 +4192,7 @@ xd3_smatch (xd3_stream *stream, again: - IF_DEBUG2 (DP(RINT "smatch at base=%u inp=%u cksum=%u\n", base, + IF_DEBUG2 (DP(RINT "smatch at base=%"W"u inp=%"W"u cksum=%"W"u\n", base, stream->input_position, scksum)); /* For small matches, we can always go to the end-of-input because @@ -4432,7 +4432,7 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) if (blkpos < (ssize_t) stream->smatcher.large_look) { stream->srcwin_cksum_pos = (blkno + 1) * stream->src->blksize; - IF_DEBUG2 (DP(RINT "[srcwin_move_point] continue (end-of-block): %"Q"u\n", blkpos)); + IF_DEBUG2 (DP(RINT "[srcwin_move_point] continue (end-of-block): %"Z"d\n", blkpos)); continue; } @@ -4473,7 +4473,7 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) IF_DEBUG1 (DP(RINT "[srcwin_move_point] exited loop T=%"Q"u " - "S=%"Q" EOF=%"Q" %s\n", + "S=%"Q"u EOF=%"Q"u %s\n", stream->total_in + stream->input_position, stream->srcwin_cksum_pos, xd3_source_eof (stream->src), @@ -4502,7 +4502,7 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) IF_DEBUG2 (DP(RINT "[srcwin_move_point] finished T=%"Q"u " - "S=%"Q"u L=%"Q"u EOF=%"Q"u %s again in %u\n", + "S=%"Q"u L=%"Q"u EOF=%"Q"u %s again in %"W"u\n", stream->total_in + stream->input_position, stream->srcwin_cksum_pos, target_cksum_pos, @@ -4568,7 +4568,7 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream) usize_t match_offset = 0; usize_t next_move_point = 0; - IF_DEBUG2(DP(RINT "[string_match] initial entry %u\n", stream->input_position)); + IF_DEBUG2(DP(RINT "[string_match] initial entry %"W"u\n", stream->input_position)); /* If there will be no compression due to settings or short input, * skip it entirely. */ @@ -4581,7 +4581,7 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream) * needs to be reset. */ restartloop: - IF_DEBUG2(DP(RINT "[string_match] restartloop %u\n", stream->input_position)); + IF_DEBUG2(DP(RINT "[string_match] restartloop %"W"u\n", stream->input_position)); /* If there is not enough input remaining for any kind of match, skip it. */ @@ -4754,8 +4754,8 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream) { IF_DEBUG2 ({ static int x = 0; - DP(RINT "[target match:%d] " - "(-%d) [ %u bytes ]\n", + DP(RINT "[target match:%d] " + "(-%"W"d) [ %"W"u bytes ]\n", x++, stream->input_position, stream->input_position + match_length, diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index e440f70..2046fe5 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h @@ -328,12 +328,6 @@ typedef uint32_t usize_t; #include #endif -/* XPRINT. Debug output and VCDIFF_TOOLS functions report to stderr. - * I have used an irregular style to abbreviate [fprintf(stderr, "] as - * [DP(RINT "]. */ -#define DP fprintf -#define RINT stderr, - typedef struct _xd3_stream xd3_stream; typedef struct _xd3_source xd3_source; typedef struct _xd3_hash_cfg xd3_hash_cfg; @@ -372,16 +366,40 @@ typedef int (xd3_getblk_func) (xd3_stream *stream, xd3_source *source, xoff_t blkno); -/* These are internal functions to delay construction of encoding - * tables and support alternate code tables. See the comments & code - * enabled by GENERIC_ENCODE_TABLES. */ - typedef const xd3_dinst* (xd3_code_table_func) (void); -typedef int (xd3_comp_table_func) (xd3_stream *stream, - const uint8_t **data, - usize_t *size); +#ifdef _WIN32 +#define vsnprintf_func _vsnprintf +#define snprintf_func _snprintf +#else +#define vsnprintf_func vsnprintf +#define snprintf_func snprintf +#endif +#define short_sprintf(sb,fmt,...) \ + snprintf_func((sb).buf,sizeof((sb).buf),fmt,__VA_ARGS__) + +/* Type used for short snprintf calls. */ +typedef struct { + char buf[48]; +} shortbuf; + +#ifndef PRINTF_ATTRIBUTE +#define PRINTF_ATTRIBUTE(x,y) __attribute__ ((__format__ (__printf__, x, y))) +#endif + +/* Underlying xprintf() */ +int xsnprintf_func (char *str, size_t n, const char *fmt, ...) + PRINTF_ATTRIBUTE(3,4); + +/* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */ +void xprintf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); +#define XPR xprintf +#define NT "xdelta3: " +#define NTR "" +/* DP(RINT ...) */ +#define DP xprintf +#define RINT "" #if XD3_DEBUG #define XD3_ASSERT(x) \ @@ -1048,7 +1066,6 @@ struct _xd3_stream xd3_desect data_sect; xd3_code_table_func *code_table_func; - xd3_comp_table_func *comp_table_func; const xd3_dinst *code_table; const xd3_code_table_desc *code_table_desc; xd3_dinst *code_table_alloc; -- cgit v1.2.3