summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh MacDonald <josh.macdonald@gmail.com>2014-10-19 00:56:02 -0700
committerJosh MacDonald <josh.macdonald@gmail.com>2014-10-19 00:56:02 -0700
commitbcb07d68e689c0641be5a5d9b692b779aa9deeb0 (patch)
tree6bf0c60f597921b4ac8abbd3d0127a4d6aadc7da
parentbf0c8992055b4e66488a2b8de56c353c573268ac (diff)
Support for 64bit usize_t w/ XD3_USE_LARGEWINDOW64
-rw-r--r--xdelta3/Makefile.am5
-rw-r--r--xdelta3/xdelta3-blkcache.h22
-rw-r--r--xdelta3/xdelta3-decode.h29
-rw-r--r--xdelta3/xdelta3-djw.h4
-rw-r--r--xdelta3/xdelta3-main.h85
-rw-r--r--xdelta3/xdelta3-second.h2
-rw-r--r--xdelta3/xdelta3-test.h39
-rw-r--r--xdelta3/xdelta3.c48
-rw-r--r--xdelta3/xdelta3.h93
9 files changed, 184 insertions, 143 deletions
diff --git a/xdelta3/Makefile.am b/xdelta3/Makefile.am
index 3907351..9369100 100644
--- a/xdelta3/Makefile.am
+++ b/xdelta3/Makefile.am
@@ -38,7 +38,7 @@ xdelta3regtest_SOURCES = $(common_SOURCES) \
38# Note: for extra sanity checks, enable -Wconversion. Note there 38# Note: for extra sanity checks, enable -Wconversion. Note there
39# are a lot of false positives. 39# are a lot of false positives.
40WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \ 40WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \
41 -Wextra -Wno-unused-parameter -Wconversion 41 -Wextra -Wno-unused-parameter # -Wconversion
42 42
43 43
44C_WFLAGS = $(WFLAGS) -pedantic -std=c99 44C_WFLAGS = $(WFLAGS) -pedantic -std=c99
@@ -50,6 +50,7 @@ common_CFLAGS = \
50 -DSECONDARY_FGK=1 \ 50 -DSECONDARY_FGK=1 \
51 -DXD3_POSIX=1 \ 51 -DXD3_POSIX=1 \
52 -DXD3_USE_LARGEFILE64=1 \ 52 -DXD3_USE_LARGEFILE64=1 \
53 -DXD3_USE_LARGEWINDOW64=1 \
53 -DXD3_MAIN=1 54 -DXD3_MAIN=1
54 55
55if DEBUG_SYMBOLS 56if DEBUG_SYMBOLS
@@ -57,7 +58,7 @@ if DEBUG_SYMBOLS
57endif 58endif
58 59
59# For additional debugging, add -DXD3_DEBUG=1, 2, 3, ... 60# For additional debugging, add -DXD3_DEBUG=1, 2, 3, ...
60xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=0 61xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=3
61xdelta3_LDADD = -lm 62xdelta3_LDADD = -lm
62 63
63xdelta3decode_CFLAGS = \ 64xdelta3decode_CFLAGS = \
diff --git a/xdelta3/xdelta3-blkcache.h b/xdelta3/xdelta3-blkcache.h
index e73a2ab..839ba33 100644
--- a/xdelta3/xdelta3-blkcache.h
+++ b/xdelta3/xdelta3-blkcache.h
@@ -246,7 +246,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
246 246
247 if (sfile->size_known) 247 if (sfile->size_known)
248 { 248 {
249 short_sprintf (srcszbuf, "source size %s [%"Q"u]", 249 short_sprintf (srcszbuf, "source size %s [%"Q"]",
250 main_format_bcnt (source_size, &srccntbuf), 250 main_format_bcnt (source_size, &srccntbuf),
251 source_size); 251 source_size);
252 } 252 }
@@ -259,7 +259,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd,
259 259
260 if (option_verbose > 1) 260 if (option_verbose > 1)
261 { 261 {
262 short_sprintf (nbufs, " #bufs %u", lru_size); 262 short_sprintf (nbufs, " #bufs %"Z, lru_size);
263 } 263 }
264 264
265 XPR(NT "source %s %s blksize %s window %s%s%s\n", 265 XPR(NT "source %s %s blksize %s window %s%s%s\n",
@@ -366,7 +366,7 @@ main_read_seek_source (xd3_stream *stream,
366 if (!option_quiet) 366 if (!option_quiet)
367 { 367 {
368 XPR(NT "source can't seek backwards; requested block offset " 368 XPR(NT "source can't seek backwards; requested block offset "
369 "%"Q"u source position is %"Q"u\n", 369 "%"Q" source position is %"Q"\n",
370 pos, sfile->source_position); 370 pos, sfile->source_position);
371 } 371 }
372 372
@@ -386,7 +386,7 @@ main_read_seek_source (xd3_stream *stream,
386 386
387 if (option_verbose > 1) 387 if (option_verbose > 1)
388 { 388 {
389 XPR(NT "seek error at offset %"Q"u: %s\n", 389 XPR(NT "seek error at offset %"Q": %s\n",
390 pos, xd3_mainerror (ret)); 390 pos, xd3_mainerror (ret));
391 } 391 }
392 } 392 }
@@ -395,7 +395,7 @@ main_read_seek_source (xd3_stream *stream,
395 395
396 if (option_verbose > 1 && pos != sfile->source_position) 396 if (option_verbose > 1 && pos != sfile->source_position)
397 { 397 {
398 XPR(NT "non-seekable source skipping %"Q"u bytes @ %"Q"u\n", 398 XPR(NT "non-seekable source skipping %"Q" bytes @ %"Q"\n",
399 pos - sfile->source_position, 399 pos - sfile->source_position,
400 sfile->source_position); 400 sfile->source_position);
401 } 401 }
@@ -440,7 +440,7 @@ main_read_seek_source (xd3_stream *stream,
440 sfile->source_position += nread; 440 sfile->source_position += nread;
441 blru->size = nread; 441 blru->size = nread;
442 442
443 IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q"u size %u\n", 443 IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q" size %u\n",
444 skip_blkno, blru->size)); 444 skip_blkno, blru->size));
445 445
446 XD3_ASSERT (sfile->source_position <= pos); 446 XD3_ASSERT (sfile->source_position <= pos);
@@ -536,20 +536,20 @@ main_getblk_func (xd3_stream *stream,
536 { 536 {
537 if (blru->blkno != blkno) 537 if (blru->blkno != blkno)
538 { 538 {
539 XPR(NT "source block %"Q"u read %zu ejects %"Q"u (lru_hits=%u, " 539 XPR(NT "source block %"Q" read %zu ejects %"Q" (lru_hits=%u, "
540 "lru_misses=%u, lru_filled=%u)\n", 540 "lru_misses=%u, lru_filled=%u)\n",
541 blkno, nread, blru->blkno, lru_hits, lru_misses, lru_filled); 541 blkno, nread, blru->blkno, lru_hits, lru_misses, lru_filled);
542 } 542 }
543 else 543 else
544 { 544 {
545 XPR(NT "source block %"Q"u read %zu (lru_hits=%u, " 545 XPR(NT "source block %"Q" read %zu (lru_hits=%u, "
546 "lru_misses=%u, lru_filled=%u)\n", 546 "lru_misses=%u, lru_filled=%u)\n",
547 blkno, nread, lru_hits, lru_misses, lru_filled); 547 blkno, nread, lru_hits, lru_misses, lru_filled);
548 } 548 }
549 } 549 }
550 else 550 else
551 { 551 {
552 XPR(NT "source block %"Q"u read %zu (lru_hits=%u, lru_misses=%u, " 552 XPR(NT "source block %"Q" read %zu (lru_hits=%u, lru_misses=%u, "
553 "lru_filled=%u)\n", blkno, nread, 553 "lru_filled=%u)\n", blkno, nread,
554 lru_hits, lru_misses, lru_filled); 554 lru_hits, lru_misses, lru_filled);
555 } 555 }
@@ -561,8 +561,8 @@ main_getblk_func (xd3_stream *stream,
561 blru->size = nread; 561 blru->size = nread;
562 blru->blkno = blkno; 562 blru->blkno = blkno;
563 563
564 IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q"u onblk %zu pos %"Q"u " 564 IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q" onblk %zu pos %"Q" "
565 "srcpos %"Q"u\n", 565 "srcpos %"Q"\n",
566 blkno, nread, pos, sfile->source_position)); 566 blkno, nread, pos, sfile->source_position));
567 567
568 return 0; 568 return 0;
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h
index b0051aa..c95f8b5 100644
--- a/xdelta3/xdelta3-decode.h
+++ b/xdelta3/xdelta3-decode.h
@@ -224,13 +224,14 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst)
224 { 224 {
225 IF_DEBUG2 ({ 225 IF_DEBUG2 ({
226 static int cnt = 0; 226 static int cnt = 0;
227 XPR(NT "DECODE:%u: COPY at %"Q"u (winoffset %u) size %u winaddr %u\n", 227 XPR(NT "DECODE:%u: COPY at %"Q" (winoffset %"Z") "
228 cnt++, 228 "size %"Z" winaddr %"Z"\n",
229 stream->total_out + (stream->dec_position - 229 cnt++,
230 stream->dec_cpylen), 230 stream->total_out + (stream->dec_position -
231 (stream->dec_position - stream->dec_cpylen), 231 stream->dec_cpylen),
232 inst->size, 232 (stream->dec_position - stream->dec_cpylen),
233 inst->addr); 233 inst->size,
234 inst->addr);
234 }); 235 });
235 236
236 if ((ret = xd3_decode_address (stream, 237 if ((ret = xd3_decode_address (stream,
@@ -265,7 +266,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst)
265 if (inst->type == XD3_ADD) 266 if (inst->type == XD3_ADD)
266 { 267 {
267 static int cnt; 268 static int cnt;
268 XPR(NT "DECODE:%d: ADD at %"Q"u (winoffset %u) size %u\n", 269 XPR(NT "DECODE:%d: ADD at %"Q" (winoffset %"Z") size %"Z"\n",
269 cnt++, 270 cnt++,
270 (stream->total_out + stream->dec_position - stream->dec_cpylen), 271 (stream->total_out + stream->dec_position - stream->dec_cpylen),
271 stream->dec_position - stream->dec_cpylen, 272 stream->dec_position - stream->dec_cpylen,
@@ -275,7 +276,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst)
275 { 276 {
276 static int cnt; 277 static int cnt;
277 XD3_ASSERT (inst->type == XD3_RUN); 278 XD3_ASSERT (inst->type == XD3_RUN);
278 XPR(NT "DECODE:%d: RUN at %"Q"u (winoffset %u) size %u\n", 279 XPR(NT "DECODE:%d: RUN at %"Q" (winoffset %"Z") size %"Z"\n",
279 cnt++, 280 cnt++,
280 stream->total_out + stream->dec_position - stream->dec_cpylen, 281 stream->total_out + stream->dec_position - stream->dec_cpylen,
281 stream->dec_position - stream->dec_cpylen, 282 stream->dec_position - stream->dec_cpylen,
@@ -453,8 +454,8 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst)
453 if ((source->onblk != blksize) && 454 if ((source->onblk != blksize) &&
454 (blkoff + take > source->onblk)) 455 (blkoff + take > source->onblk))
455 { 456 {
456 IF_DEBUG1 (XPR(NT "[srcfile] short at blkno %"Q"u onblk " 457 IF_DEBUG1 (XPR(NT "[srcfile] short at blkno %"Q" onblk "
457 "%u blksize %u blkoff %u take %u\n", 458 "%"Z" blksize %"Z" blkoff %"Z" take %"Z"\n",
458 block, 459 block,
459 source->onblk, 460 source->onblk,
460 blksize, 461 blksize,
@@ -916,7 +917,7 @@ xd3_decode_input (xd3_stream *stream)
916 917
917 stream->dec_state = DEC_CPYLEN; 918 stream->dec_state = DEC_CPYLEN;
918 919
919 IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q"u -----------\n", 920 IF_DEBUG2 (DP(RINT "--------- TARGET WINDOW %"Q" -----------\n",
920 stream->current_window)); 921 stream->current_window));
921 } 922 }
922 923
@@ -1073,8 +1074,8 @@ xd3_decode_input (xd3_stream *stream)
1073 &src->cpyoff_blkoff); 1074 &src->cpyoff_blkoff);
1074 1075
1075 IF_DEBUG1(DP(RINT 1076 IF_DEBUG1(DP(RINT
1076 "decode cpyoff %"Q"u " 1077 "decode cpyoff %"Q" "
1077 "cpyblkno %"Q"u " 1078 "cpyblkno %"Q" "
1078 "cpyblkoff %u " 1079 "cpyblkoff %u "
1079 "blksize %u\n", 1080 "blksize %u\n",
1080 stream->dec_cpyoff, 1081 stream->dec_cpyoff,
diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h
index cba061e..729f492 100644
--- a/xdelta3/xdelta3-djw.h
+++ b/xdelta3/xdelta3-djw.h
@@ -493,8 +493,8 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
493 { 493 {
494 IF_DEBUG2 (if (first_bits != total_bits) 494 IF_DEBUG2 (if (first_bits != total_bits)
495 { 495 {
496 DP(RINT "code length overflow changed %u bits\n", 496 DP(RINT "code length overflow changed %"Z" bits\n",
497 (usize_t)(total_bits - first_bits)); 497 total_bits - first_bits);
498 }); 498 });
499 return total_bits; 499 return total_bits;
500 } 500 }
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 108a71a..030bc85 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -383,6 +383,7 @@ main_config (void)
383 XPR(NTR "XD3_STDIO=%d\n", XD3_STDIO); 383 XPR(NTR "XD3_STDIO=%d\n", XD3_STDIO);
384 XPR(NTR "XD3_WIN32=%d\n", XD3_WIN32); 384 XPR(NTR "XD3_WIN32=%d\n", XD3_WIN32);
385 XPR(NTR "XD3_USE_LARGEFILE64=%d\n", XD3_USE_LARGEFILE64); 385 XPR(NTR "XD3_USE_LARGEFILE64=%d\n", XD3_USE_LARGEFILE64);
386 XPR(NTR "XD3_USE_LARGEWINDOW64=%d\n", XD3_USE_LARGEWINDOW64);
386 XPR(NTR "XD3_DEFAULT_LEVEL=%d\n", XD3_DEFAULT_LEVEL); 387 XPR(NTR "XD3_DEFAULT_LEVEL=%d\n", XD3_DEFAULT_LEVEL);
387 XPR(NTR "XD3_DEFAULT_IOPT_SIZE=%d\n", XD3_DEFAULT_IOPT_SIZE); 388 XPR(NTR "XD3_DEFAULT_IOPT_SIZE=%d\n", XD3_DEFAULT_IOPT_SIZE);
388 XPR(NTR "XD3_DEFAULT_SPREVSZ=%d\n", XD3_DEFAULT_SPREVSZ); 389 XPR(NTR "XD3_DEFAULT_SPREVSZ=%d\n", XD3_DEFAULT_SPREVSZ);
@@ -610,7 +611,7 @@ main_format_bcnt (xoff_t r, shortbuf *buf)
610 611
611 if (r >= 100 && r < 1000) 612 if (r >= 100 && r < 1000)
612 { 613 {
613 short_sprintf (*buf, "%"Q"u %s", r, fmts[i]); 614 short_sprintf (*buf, "%"Q" %s", r, fmts[i]);
614 return buf->buf; 615 return buf->buf;
615 } 616 }
616 617
@@ -710,12 +711,12 @@ main_atoux (const char* arg, xoff_t *xo, xoff_t low,
710 711
711 if (x < low) 712 if (x < low)
712 { 713 {
713 XPR(NT "-%c: minimum value: %"Q"u\n", which, low); 714 XPR(NT "-%c: minimum value: %"Q"\n", which, low);
714 return EXIT_FAILURE; 715 return EXIT_FAILURE;
715 } 716 }
716 if (high != 0 && x > high) 717 if (high != 0 && x > high)
717 { 718 {
718 XPR(NT "-%c: maximum value: %"Q"u\n", which, high); 719 XPR(NT "-%c: maximum value: %"Q"\n", which, high);
719 return EXIT_FAILURE; 720 return EXIT_FAILURE;
720 } 721 }
721 (*xo) = x; 722 (*xo) = x;
@@ -1105,7 +1106,7 @@ main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg)
1105 } 1106 }
1106 else 1107 else
1107 { 1108 {
1108 if (option_verbose > 5) { XPR(NT "write %s: %u bytes\n", 1109 if (option_verbose > 5) { XPR(NT "write %s: %"Z" bytes\n",
1109 ofile->filename, size); } 1110 ofile->filename, size); }
1110 ofile->nwrite += size; 1111 ofile->nwrite += size;
1111 } 1112 }
@@ -1290,7 +1291,7 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1290 1291
1291 if ((ret = xd3_decode_instruction (stream))) 1292 if ((ret = xd3_decode_instruction (stream)))
1292 { 1293 {
1293 XPR(NT "instruction decode error at %"Q"u: %s\n", 1294 XPR(NT "instruction decode error at %"Q": %s\n",
1294 stream->dec_winstart + size, stream->msg); 1295 stream->dec_winstart + size, stream->msg);
1295 return ret; 1296 return ret;
1296 } 1297 }
@@ -1298,7 +1299,8 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1298 addr_bytes = (usize_t)(stream->addr_sect.buf - addr_before); 1299 addr_bytes = (usize_t)(stream->addr_sect.buf - addr_before);
1299 inst_bytes = (usize_t)(stream->inst_sect.buf - inst_before); 1300 inst_bytes = (usize_t)(stream->inst_sect.buf - inst_before);
1300 1301
1301 VC(UT " %06"Q"u %03u %s %6u", stream->dec_winstart + size, 1302 VC(UT " %06"Q" %03"Z" %s %6"Z,
1303 stream->dec_winstart + size,
1302 option_print_cpymode ? code : 0, 1304 option_print_cpymode ? code : 0,
1303 xd3_rtype_to_string ((xd3_rtype) stream->dec_current1.type, 1305 xd3_rtype_to_string ((xd3_rtype) stream->dec_current1.type,
1304 option_print_cpymode), 1306 option_print_cpymode),
@@ -1310,12 +1312,12 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1310 { 1312 {
1311 if (stream->dec_current1.addr >= stream->dec_cpylen) 1313 if (stream->dec_current1.addr >= stream->dec_cpylen)
1312 { 1314 {
1313 VC(UT " T@%-6u", 1315 VC(UT " T@%-6"Z,
1314 stream->dec_current1.addr - stream->dec_cpylen)VE; 1316 stream->dec_current1.addr - stream->dec_cpylen)VE;
1315 } 1317 }
1316 else 1318 else
1317 { 1319 {
1318 VC(UT " S@%-6"Q"u", 1320 VC(UT " S@%-6"Q,
1319 stream->dec_cpyoff + stream->dec_current1.addr)VE; 1321 stream->dec_cpyoff + stream->dec_current1.addr)VE;
1320 } 1322 }
1321 } 1323 }
@@ -1329,7 +1331,7 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1329 1331
1330 if (stream->dec_current2.type != XD3_NOOP) 1332 if (stream->dec_current2.type != XD3_NOOP)
1331 { 1333 {
1332 VC(UT " %s %6u", 1334 VC(UT " %s %6"Z,
1333 xd3_rtype_to_string ((xd3_rtype) stream->dec_current2.type, 1335 xd3_rtype_to_string ((xd3_rtype) stream->dec_current2.type,
1334 option_print_cpymode), 1336 option_print_cpymode),
1335 stream->dec_current2.size)VE; 1337 stream->dec_current2.size)VE;
@@ -1338,12 +1340,12 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1338 { 1340 {
1339 if (stream->dec_current2.addr >= stream->dec_cpylen) 1341 if (stream->dec_current2.addr >= stream->dec_cpylen)
1340 { 1342 {
1341 VC(UT " T@%-6u", 1343 VC(UT " T@%-6"Q,
1342 stream->dec_current2.addr - stream->dec_cpylen)VE; 1344 stream->dec_current2.addr - stream->dec_cpylen)VE;
1343 } 1345 }
1344 else 1346 else
1345 { 1347 {
1346 VC(UT " S@%-6"Q"u", 1348 VC(UT " S@%-6"Q"",
1347 stream->dec_cpyoff + stream->dec_current2.addr)VE; 1349 stream->dec_cpyoff + stream->dec_current2.addr)VE;
1348 } 1350 }
1349 } 1351 }
@@ -1358,7 +1360,7 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1358 (stream->dec_current1.type >= XD3_CPY || 1360 (stream->dec_current1.type >= XD3_CPY ||
1359 stream->dec_current2.type >= XD3_CPY)) 1361 stream->dec_current2.type >= XD3_CPY))
1360 { 1362 {
1361 VC(UT " %06"Q"u (inefficiency) %u encoded as %u bytes\n", 1363 VC(UT " %06"Q" (inefficiency) %"Z" encoded as %"Z" bytes\n",
1362 stream->dec_winstart + size_before, 1364 stream->dec_winstart + size_before,
1363 size - size_before, 1365 size - size_before,
1364 addr_bytes + inst_bytes)VE; 1366 addr_bytes + inst_bytes)VE;
@@ -1426,7 +1428,7 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1426 if (stream->dec_winstart == 0) 1428 if (stream->dec_winstart == 0)
1427 { 1429 {
1428 VC(UT "VCDIFF version: 0\n")VE; 1430 VC(UT "VCDIFF version: 0\n")VE;
1429 VC(UT "VCDIFF header size: %d\n", 1431 VC(UT "VCDIFF header size: %"Z"\n",
1430 stream->dec_hdrsize)VE; 1432 stream->dec_hdrsize)VE;
1431 VC(UT "VCDIFF header indicator: ")VE; 1433 VC(UT "VCDIFF header indicator: ")VE;
1432 if ((stream->dec_hdr_ind & VCD_SECONDARY) != 0) 1434 if ((stream->dec_hdr_ind & VCD_SECONDARY) != 0)
@@ -1481,7 +1483,7 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1481 VC(UT "\n")VE; 1483 VC(UT "\n")VE;
1482 } 1484 }
1483 1485
1484 VC(UT "VCDIFF window number: %"Q"u\n", stream->current_window)VE; 1486 VC(UT "VCDIFF window number: %"Q"\n", stream->current_window)VE;
1485 VC(UT "VCDIFF window indicator: ")VE; 1487 VC(UT "VCDIFF window indicator: ")VE;
1486 if ((stream->dec_win_ind & VCD_SOURCE) != 0) VC(UT "VCD_SOURCE ")VE; 1488 if ((stream->dec_win_ind & VCD_SOURCE) != 0) VC(UT "VCD_SOURCE ")VE;
1487 if ((stream->dec_win_ind & VCD_TARGET) != 0) VC(UT "VCD_TARGET ")VE; 1489 if ((stream->dec_win_ind & VCD_TARGET) != 0) VC(UT "VCD_TARGET ")VE;
@@ -1492,7 +1494,7 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1492 if ((stream->dec_win_ind & VCD_ADLER32) != 0) 1494 if ((stream->dec_win_ind & VCD_ADLER32) != 0)
1493 { 1495 {
1494 VC(UT "VCDIFF adler32 checksum: %08X\n", 1496 VC(UT "VCDIFF adler32 checksum: %08X\n",
1495 (usize_t)stream->dec_adler32)VE; 1497 stream->dec_adler32)VE;
1496 } 1498 }
1497 1499
1498 if (stream->dec_del_ind != 0) 1500 if (stream->dec_del_ind != 0)
@@ -1507,27 +1509,27 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1507 1509
1508 if (stream->dec_winstart != 0) 1510 if (stream->dec_winstart != 0)
1509 { 1511 {
1510 VC(UT "VCDIFF window at offset: %"Q"u\n", stream->dec_winstart)VE; 1512 VC(UT "VCDIFF window at offset: %"Q"\n", stream->dec_winstart)VE;
1511 } 1513 }
1512 1514
1513 if (SRCORTGT (stream->dec_win_ind)) 1515 if (SRCORTGT (stream->dec_win_ind))
1514 { 1516 {
1515 VC(UT "VCDIFF copy window length: %u\n", 1517 VC(UT "VCDIFF copy window length: %"Z"\n",
1516 (usize_t)stream->dec_cpylen)VE; 1518 stream->dec_cpylen)VE;
1517 VC(UT "VCDIFF copy window offset: %"Q"u\n", 1519 VC(UT "VCDIFF copy window offset: %"Q"\n",
1518 stream->dec_cpyoff)VE; 1520 stream->dec_cpyoff)VE;
1519 } 1521 }
1520 1522
1521 VC(UT "VCDIFF delta encoding length: %u\n", 1523 VC(UT "VCDIFF delta encoding length: %"Z"\n",
1522 (usize_t)stream->dec_enclen)VE; 1524 (usize_t)stream->dec_enclen)VE;
1523 VC(UT "VCDIFF target window length: %u\n", 1525 VC(UT "VCDIFF target window length: %"Z"\n",
1524 (usize_t)stream->dec_tgtlen)VE; 1526 (usize_t)stream->dec_tgtlen)VE;
1525 1527
1526 VC(UT "VCDIFF data section length: %u\n", 1528 VC(UT "VCDIFF data section length: %"Z"\n",
1527 (usize_t)stream->data_sect.size)VE; 1529 (usize_t)stream->data_sect.size)VE;
1528 VC(UT "VCDIFF inst section length: %u\n", 1530 VC(UT "VCDIFF inst section length: %"Z"\n",
1529 (usize_t)stream->inst_sect.size)VE; 1531 (usize_t)stream->inst_sect.size)VE;
1530 VC(UT "VCDIFF addr section length: %u\n", 1532 VC(UT "VCDIFF addr section length: %"Z"\n",
1531 (usize_t)stream->addr_sect.size)VE; 1533 (usize_t)stream->addr_sect.size)VE;
1532 1534
1533 ret = 0; 1535 ret = 0;
@@ -1967,8 +1969,11 @@ main_merge_output (xd3_stream *stream, main_file *ofile)
1967 XD3_ASSERT (inst->addr >= window_start); 1969 XD3_ASSERT (inst->addr >= window_start);
1968 addr = inst->addr - window_start; 1970 addr = inst->addr - window_start;
1969 } 1971 }
1970 IF_DEBUG2 (XPR(NTR "[merge copy] winpos %u take %u addr %"Q"u mode %u\n", 1972 IF_DEBUG2 ({
1971 window_pos, take, addr, inst->mode)); 1973 XPR(NTR "[merge copy] winpos %"Z" take %"Z" "
1974 "addr %"Q" mode %u\n",
1975 window_pos, take, addr, inst->mode);
1976 });
1972 if ((ret = xd3_found_match (recode_stream, window_pos, take, 1977 if ((ret = xd3_found_match (recode_stream, window_pos, take,
1973 addr, inst->mode != 0))) 1978 addr, inst->mode != 0)))
1974 { 1979 {
@@ -2243,7 +2248,7 @@ main_pipe_copier (uint8_t *pipe_buf,
2243 2248
2244 if (option_verbose && skipped != 0) 2249 if (option_verbose && skipped != 0)
2245 { 2250 {
2246 XPR(NT "skipping %"Q"u bytes in %s\n", 2251 XPR(NT "skipping %"Q" bytes in %s\n",
2247 skipped, ifile->filename); 2252 skipped, ifile->filename);
2248 } 2253 }
2249 return 0; 2254 return 0;
@@ -3041,7 +3046,7 @@ main_input (xd3_cmd cmd,
3041 { 3046 {
3042 const char *s = option_smatch_config; 3047 const char *s = option_smatch_config;
3043 char *e; 3048 char *e;
3044 usize_t values[XD3_SOFTCFG_VARCNT]; 3049 long values[XD3_SOFTCFG_VARCNT];
3045 int got; 3050 int got;
3046 3051
3047 config.smatch_cfg = XD3_SMATCH_SOFT; 3052 config.smatch_cfg = XD3_SMATCH_SOFT;
@@ -3284,7 +3289,7 @@ main_input (xd3_cmd cmd,
3284 /* Warn when no source copies are found */ 3289 /* Warn when no source copies are found */
3285 if (option_verbose && ! xd3_encoder_used_source (& stream)) 3290 if (option_verbose && ! xd3_encoder_used_source (& stream))
3286 { 3291 {
3287 XPR(NT "warning: input window %"Q"u..%"Q"u has " 3292 XPR(NT "warning: input window %"Q"..%"Q" has "
3288 "no source copies\n", 3293 "no source copies\n",
3289 stream.current_window * winsize, 3294 stream.current_window * winsize,
3290 (stream.current_window+1) * winsize); 3295 (stream.current_window+1) * winsize);
@@ -3297,8 +3302,8 @@ main_input (xd3_cmd cmd,
3297 stream.srcwin_decided_early && 3302 stream.srcwin_decided_early &&
3298 stream.i_slots_used > stream.iopt_size) 3303 stream.i_slots_used > stream.iopt_size)
3299 { 3304 {
3300 XPR(NT "warning: input position %"Q"u overflowed " 3305 XPR(NT "warning: input position %"Q" overflowed "
3301 "instruction buffer, needed %u (vs. %u), " 3306 "instruction buffer, needed %"Z" (vs. %"Z"), "
3302 "consider changing -I\n", 3307 "consider changing -I\n",
3303 stream.current_window * winsize, 3308 stream.current_window * winsize,
3304 stream.i_slots_used, stream.iopt_size); 3309 stream.i_slots_used, stream.iopt_size);
@@ -3321,7 +3326,7 @@ main_input (xd3_cmd cmd,
3321 3326
3322 if (option_verbose > 1) 3327 if (option_verbose > 1)
3323 { 3328 {
3324 XPR(NT "%"Q"u: in %s (%s): out %s (%s): " 3329 XPR(NT "%"Q": in %s (%s): out %s (%s): "
3325 "total in %s: out %s: %s: srcpos %s\n", 3330 "total in %s: out %s: %s: srcpos %s\n",
3326 stream.current_window, 3331 stream.current_window,
3327 main_format_bcnt (this_read, &rdb), 3332 main_format_bcnt (this_read, &rdb),
@@ -3335,7 +3340,7 @@ main_input (xd3_cmd cmd,
3335 } 3340 }
3336 else 3341 else
3337 { 3342 {
3338 XPR(NT "%"Q"u: in %s: out %s: total in %s: " 3343 XPR(NT "%"Q": in %s: out %s: total in %s: "
3339 "out %s: %s\n", 3344 "out %s: %s\n",
3340 stream.current_window, 3345 stream.current_window,
3341 main_format_bcnt (this_read, &rdb), 3346 main_format_bcnt (this_read, &rdb),
@@ -3422,21 +3427,21 @@ done:
3422 if (option_verbose > 1 && cmd == CMD_ENCODE) 3427 if (option_verbose > 1 && cmd == CMD_ENCODE)
3423 { 3428 {
3424 XPR(NT "scanner configuration: %s\n", stream.smatcher.name); 3429 XPR(NT "scanner configuration: %s\n", stream.smatcher.name);
3425 XPR(NT "target hash table size: %u\n", stream.small_hash.size); 3430 XPR(NT "target hash table size: %"Z"\n", stream.small_hash.size);
3426 if (sfile != NULL && sfile->filename != NULL) 3431 if (sfile != NULL && sfile->filename != NULL)
3427 { 3432 {
3428 XPR(NT "source hash table size: %u\n", stream.large_hash.size); 3433 XPR(NT "source hash table size: %"Z"\n", stream.large_hash.size);
3429 } 3434 }
3430 } 3435 }
3431 3436
3432 if (option_verbose > 2 && cmd == CMD_ENCODE) 3437 if (option_verbose > 2 && cmd == CMD_ENCODE)
3433 { 3438 {
3434 XPR(NT "source copies: %"Q"u (%"Q"u bytes)\n", 3439 XPR(NT "source copies: %"Q" (%"Q" bytes)\n",
3435 stream.n_scpy, stream.l_scpy); 3440 stream.n_scpy, stream.l_scpy);
3436 XPR(NT "target copies: %"Q"u (%"Q"u bytes)\n", 3441 XPR(NT "target copies: %"Q" (%"Q" bytes)\n",
3437 stream.n_tcpy, stream.l_tcpy); 3442 stream.n_tcpy, stream.l_tcpy);
3438 XPR(NT "adds: %"Q"u (%"Q"u bytes)\n", stream.n_add, stream.l_add); 3443 XPR(NT "adds: %"Q" (%"Q" bytes)\n", stream.n_add, stream.l_add);
3439 XPR(NT "runs: %"Q"u (%"Q"u bytes)\n", stream.n_run, stream.l_run); 3444 XPR(NT "runs: %"Q" (%"Q" bytes)\n", stream.n_run, stream.l_run);
3440 } 3445 }
3441#endif 3446#endif
3442 3447
@@ -3448,7 +3453,7 @@ done:
3448 long end_time = get_millisecs_now (); 3453 long end_time = get_millisecs_now ();
3449 xoff_t nwrite = ofile != NULL ? ofile->nwrite : 0; 3454 xoff_t nwrite = ofile != NULL ? ofile->nwrite : 0;
3450 3455
3451 XPR(NT "finished in %s; input %"Q"u output %"Q"u bytes (%0.2f%%)\n", 3456 XPR(NT "finished in %s; input %"Q" output %"Q" bytes (%0.2f%%)\n",
3452 main_format_millis (end_time - start_time, &tm), 3457 main_format_millis (end_time - start_time, &tm),
3453 ifile->nread, nwrite, 100.0 * nwrite / ifile->nread); 3458 ifile->nread, nwrite, 100.0 * nwrite / ifile->nread);
3454 } 3459 }
diff --git a/xdelta3/xdelta3-second.h b/xdelta3/xdelta3-second.h
index 1c8a406..098a5d5 100644
--- a/xdelta3/xdelta3-second.h
+++ b/xdelta3/xdelta3-second.h
@@ -122,7 +122,7 @@ xd3_decode_secondary (xd3_stream *stream,
122 xd3_desect *sect, 122 xd3_desect *sect,
123 xd3_sec_stream **sec_streamp) 123 xd3_sec_stream **sec_streamp)
124{ 124{
125 uint32_t dec_size; 125 usize_t dec_size;
126 uint8_t *out_used; 126 uint8_t *out_used;
127 int ret; 127 int ret;
128 128
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h
index 948a1d6..3d505fc 100644
--- a/xdelta3/xdelta3-test.h
+++ b/xdelta3/xdelta3-test.h
@@ -139,7 +139,10 @@ static char TEST_RECON2_FILE[TESTFILESIZE];
139static char TEST_COPY_FILE[TESTFILESIZE]; 139static char TEST_COPY_FILE[TESTFILESIZE];
140static char TEST_NOPERM_FILE[TESTFILESIZE]; 140static char TEST_NOPERM_FILE[TESTFILESIZE];
141 141
142#define CHECK(cond) if (!(cond)) { XPR(NT "check failure: " #cond); abort(); } 142#define CHECK(cond) \
143 if (!(cond)) { \
144 XPR(NT __FILE__":%d: check failure: " #cond, __LINE__); \
145 abort(); }
143 146
144#if SHELL_TESTS 147#if SHELL_TESTS
145/* Use a fixed soft config so that test values are fixed. See also 148/* Use a fixed soft config so that test values are fixed. See also
@@ -199,7 +202,7 @@ test_random_numbers (xd3_stream *stream, int ignore)
199 202
200 for (i = 0; i < n_rounds; i += 1) 203 for (i = 0; i < n_rounds; i += 1)
201 { 204 {
202 sum += mt_exp_rand (mean, USIZE_T_MAX); 205 sum += mt_exp_rand (mean, UINT32_MAX);
203 } 206 }
204 207
205 average = (double) sum / (double) n_rounds; 208 average = (double) sum / (double) n_rounds;
@@ -411,7 +414,7 @@ test_compare_files (const char* tgt, const char *rec)
411 { 414 {
412 if (obuf[i] != rbuf[i]) 415 if (obuf[i] != rbuf[i])
413 { 416 {
414 XPR(NT "byte %u (read %u @ %"Q"u) %d != %d\n", 417 XPR(NT "byte %u (read %u @ %"Q") %d != %d\n",
415 (int)i, (int)oc, offset, obuf[i], rbuf[i]); 418 (int)i, (int)oc, offset, obuf[i], rbuf[i]);
416 diffs++; 419 diffs++;
417 return XD3_INTERNAL; 420 return XD3_INTERNAL;
@@ -677,13 +680,13 @@ test_forward_match (xd3_stream *stream, int unused)
677 680
678 for (i = 0; i < 256; i++) 681 for (i = 0; i < 256; i++)
679 { 682 {
680 CHECK(xd3_forward_match(buf1, buf2, i) == (int)i); 683 CHECK(xd3_forward_match(buf1, buf2, i) == i);
681 } 684 }
682 685
683 for (i = 0; i < 255; i++) 686 for (i = 0; i < 255; i++)
684 { 687 {
685 buf2[i] = 1; 688 buf2[i] = 1;
686 CHECK(xd3_forward_match(buf1, buf2, 256) == (int)i); 689 CHECK(xd3_forward_match(buf1, buf2, 256) == i);
687 buf2[i] = 0; 690 buf2[i] = 0;
688 } 691 }
689 692
@@ -732,7 +735,7 @@ test_address_cache (xd3_stream *stream, int unused)
732 usize_t prev_i; 735 usize_t prev_i;
733 usize_t nearby; 736 usize_t nearby;
734 737
735 p = (mt_random (&static_mtrand) / (double)USIZE_T_MAX); 738 p = (mt_random (&static_mtrand) / (double)UINT32_MAX);
736 prev_i = mt_random (&static_mtrand) % offset; 739 prev_i = mt_random (&static_mtrand) % offset;
737 nearby = (mt_random (&static_mtrand) % 256) % offset; 740 nearby = (mt_random (&static_mtrand) % 256) % offset;
738 nearby = max (1U, nearby); 741 nearby = max (1U, nearby);
@@ -763,9 +766,13 @@ test_address_cache (xd3_stream *stream, int unused)
763 766
764 for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) 767 for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1)
765 { 768 {
766 uint32_t addr; 769 usize_t addr;
767 770
768 if ((ret = xd3_decode_address (stream, offset, modes[offset], & buf, buf_max, & addr))) { return ret; } 771 if ((ret = xd3_decode_address (stream, offset, modes[offset],
772 & buf, buf_max, & addr)))
773 {
774 return ret;
775 }
769 776
770 if (addr != addrs[offset]) 777 if (addr != addrs[offset])
771 { 778 {
@@ -1391,7 +1398,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups)
1391 if ((ret = sec->encode (stream, enc_stream, 1398 if ((ret = sec->encode (stream, enc_stream,
1392 in_head, out_head, & cfg))) 1399 in_head, out_head, & cfg)))
1393 { 1400 {
1394 XPR(NT "test %u: encode: %s", test_i, stream->msg); 1401 XPR(NT "test %"Z": encode: %s", test_i, stream->msg);
1395 goto fail; 1402 goto fail;
1396 } 1403 }
1397 1404
@@ -1430,7 +1437,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups)
1430 compress_size, dec_input, 1437 compress_size, dec_input,
1431 dec_correct, dec_output))) 1438 dec_correct, dec_output)))
1432 { 1439 {
1433 XPR(NT "test %u: decode: %s", test_i, stream->msg); 1440 XPR(NT "test %"Z": decode: %s", test_i, stream->msg);
1434 goto fail; 1441 goto fail;
1435 } 1442 }
1436 1443
@@ -1759,7 +1766,7 @@ test_command_line_arguments (xd3_stream *stream, int ignore)
1759 if (ratio >= TEST_ADD_RATIO + TEST_EPSILON) 1766 if (ratio >= TEST_ADD_RATIO + TEST_EPSILON)
1760 { 1767 {
1761 XPR(NT "test encode with size ratio %.4f, " 1768 XPR(NT "test encode with size ratio %.4f, "
1762 "expected < %.4f (%"Q"u, %"Q"u)\n", 1769 "expected < %.4f (%"Q", %"Q")\n",
1763 ratio, TEST_ADD_RATIO + TEST_EPSILON, dsize, tsize); 1770 ratio, TEST_ADD_RATIO + TEST_EPSILON, dsize, tsize);
1764 stream->msg = "strange encoding"; 1771 stream->msg = "strange encoding";
1765 return XD3_INTERNAL; 1772 return XD3_INTERNAL;
@@ -2645,14 +2652,14 @@ test_string_matching (xd3_stream *stream, int ignore)
2645 default: CHECK(0); 2652 default: CHECK(0);
2646 } 2653 }
2647 2654
2648 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%d/%d", 2655 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Z"/%"Z"",
2649 inst->pos, inst->size); 2656 inst->pos, inst->size);
2650 rptr += strlen (rptr); 2657 rptr += strlen (rptr);
2651 2658
2652 if (inst->type == XD3_CPY) 2659 if (inst->type == XD3_CPY)
2653 { 2660 {
2654 *rptr++ = '@'; 2661 *rptr++ = '@';
2655 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q"d", inst->addr); 2662 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q, inst->addr);
2656 rptr += strlen (rptr); 2663 rptr += strlen (rptr);
2657 } 2664 }
2658 2665
@@ -2668,7 +2675,7 @@ test_string_matching (xd3_stream *stream, int ignore)
2668 2675
2669 if (strcmp (rbuf, test->result) != 0) 2676 if (strcmp (rbuf, test->result) != 0)
2670 { 2677 {
2671 XPR(NT "test %u: expected %s: got %s", i, test->result, rbuf); 2678 XPR(NT "test %"Z": expected %s: got %s", i, test->result, rbuf);
2672 stream->msg = "wrong result"; 2679 stream->msg = "wrong result";
2673 return XD3_INTERNAL; 2680 return XD3_INTERNAL;
2674 } 2681 }
@@ -2743,6 +2750,7 @@ test_iopt_flush_instructions (xd3_stream *stream, int ignore)
2743/* 2750/*
2744 * This tests the 32/64bit ambiguity for source-window matching. 2751 * This tests the 32/64bit ambiguity for source-window matching.
2745 */ 2752 */
2753#if !XD3_USE_LARGEWINDOW64
2746static int 2754static int
2747test_source_cksum_offset (xd3_stream *stream, int ignore) 2755test_source_cksum_offset (xd3_stream *stream, int ignore)
2748{ 2756{
@@ -2788,6 +2796,7 @@ test_source_cksum_offset (xd3_stream *stream, int ignore)
2788 } 2796 }
2789 return 0; 2797 return 0;
2790} 2798}
2799#endif /* !XD3_USE_LARGEWINDOW64 */
2791 2800
2792static int 2801static int
2793test_in_memory (xd3_stream *stream, int ignore) 2802test_in_memory (xd3_stream *stream, int ignore)
@@ -2868,7 +2877,9 @@ xd3_selftest (void)
2868 DO_TEST (in_memory, 0, 0); 2877 DO_TEST (in_memory, 0, 0);
2869 2878
2870 DO_TEST (iopt_flush_instructions, 0, 0); 2879 DO_TEST (iopt_flush_instructions, 0, 0);
2880#if !XD3_USE_LARGEWINDOW64
2871 DO_TEST (source_cksum_offset, 0, 0); 2881 DO_TEST (source_cksum_offset, 0, 0);
2882#endif
2872 2883
2873 DO_TEST (decompress_single_bit_error, 0, 3); 2884 DO_TEST (decompress_single_bit_error, 0, 3);
2874 DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3); 2885 DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3);
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index c17a298..e194681 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -1644,7 +1644,7 @@ xd3_encode_address (xd3_stream *stream,
1644static int 1644static int
1645xd3_decode_address (xd3_stream *stream, usize_t here, 1645xd3_decode_address (xd3_stream *stream, usize_t here,
1646 usize_t mode, const uint8_t **inpp, 1646 usize_t mode, const uint8_t **inpp,
1647 const uint8_t *max, uint32_t *valp) 1647 const uint8_t *max, usize_t *valp)
1648{ 1648{
1649 int ret; 1649 int ret;
1650 usize_t same_start = 2 + stream->acache.s_near; 1650 usize_t same_start = 2 + stream->acache.s_near;
@@ -2164,11 +2164,11 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno)
2164 ret = stream->getblk (stream, source, blkno); 2164 ret = stream->getblk (stream, source, blkno);
2165 if (ret != 0) 2165 if (ret != 0)
2166 { 2166 {
2167 IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q"u: %s\n", 2167 IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q": %s\n",
2168 blkno, xd3_strerror (ret))); 2168 blkno, xd3_strerror (ret)));
2169 return ret; 2169 return ret;
2170 } 2170 }
2171 IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q"u onblk " 2171 IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q" onblk "
2172 "%u blksize %u\n", blkno, source->onblk, source->blksize)); 2172 "%u blksize %u\n", blkno, source->onblk, source->blksize));
2173 } 2173 }
2174 2174
@@ -2184,8 +2184,8 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno)
2184 { 2184 {
2185 source->frontier_blkno = blkno + 1; 2185 source->frontier_blkno = blkno + 1;
2186 2186
2187 IF_DEBUG2 (DP(RINT "[getblk] full source blkno %"Q"u: " 2187 IF_DEBUG2 (DP(RINT "[getblk] full source blkno %"Q": "
2188 "source length unknown %"Q"u\n", 2188 "source length unknown %"Q"\n",
2189 blkno, 2189 blkno,
2190 xd3_source_eof (source))); 2190 xd3_source_eof (source)));
2191 } 2191 }
@@ -2194,7 +2194,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno)
2194 if (!source->eof_known) 2194 if (!source->eof_known)
2195 { 2195 {
2196 IF_DEBUG2 (DP(RINT "[getblk] eof block has %d bytes; " 2196 IF_DEBUG2 (DP(RINT "[getblk] eof block has %d bytes; "
2197 "source length known %"Q"u\n", 2197 "source length known %"Q"\n",
2198 xd3_bytes_on_srcblk (source, blkno), 2198 xd3_bytes_on_srcblk (source, blkno),
2199 xd3_source_eof (source))); 2199 xd3_source_eof (source)));
2200 source->eof_known = 1; 2200 source->eof_known = 1;
@@ -2264,7 +2264,7 @@ xd3_set_source_and_size (xd3_stream *stream,
2264 if (ret == 0) 2264 if (ret == 0)
2265 { 2265 {
2266 stream->src->eof_known = 1; 2266 stream->src->eof_known = 1;
2267 IF_DEBUG2 (DP(RINT "[set source] size known %"Q"u\n", 2267 IF_DEBUG2 (DP(RINT "[set source] size known %"Q"\n",
2268 source_size)); 2268 source_size));
2269 2269
2270 xd3_blksize_div(source_size, 2270 xd3_blksize_div(source_size,
@@ -2474,7 +2474,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst)
2474 2474
2475 IF_DEBUG2 ({ 2475 IF_DEBUG2 ({
2476 static int cnt; 2476 static int cnt;
2477 DP(RINT "[iopt copy:%d] pos %"Q"u-%"Q"u addr %"Q"u-%"Q"u size %u\n", 2477 DP(RINT "[iopt copy:%d] pos %"Q"-%"Q" addr %"Q"-%"Q" size %u\n",
2478 cnt++, 2478 cnt++,
2479 stream->total_in + inst->pos, 2479 stream->total_in + inst->pos,
2480 stream->total_in + inst->pos + inst->size, 2480 stream->total_in + inst->pos + inst->size,
@@ -2493,7 +2493,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst)
2493 2493
2494 IF_DEBUG2 ({ 2494 IF_DEBUG2 ({
2495 static int cnt; 2495 static int cnt;
2496 DP(RINT "[iopt run:%d] pos %"Q"u size %u\n", cnt++, stream->total_in + inst->pos, inst->size); 2496 DP(RINT "[iopt run:%d] pos %"Q" size %u\n", cnt++, stream->total_in + inst->pos, inst->size);
2497 }); 2497 });
2498 break; 2498 break;
2499 } 2499 }
@@ -2507,7 +2507,7 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst)
2507 2507
2508 IF_DEBUG2 ({ 2508 IF_DEBUG2 ({
2509 static int cnt; 2509 static int cnt;
2510 DP(RINT "[iopt add:%d] pos %"Q"u size %u\n", cnt++, stream->total_in + inst->pos, inst->size); 2510 DP(RINT "[iopt add:%d] pos %"Q" size %u\n", cnt++, stream->total_in + inst->pos, inst->size);
2511 }); 2511 });
2512 2512
2513 break; 2513 break;
@@ -3410,7 +3410,7 @@ xd3_encode_input (xd3_stream *stream)
3410 3410
3411 stream->enc_state = ENC_SEARCH; 3411 stream->enc_state = ENC_SEARCH;
3412 3412
3413 IF_DEBUG2 (DP(RINT "[WINSTART:%"Q"u] input bytes %u offset %"Q"u\n", 3413 IF_DEBUG2 (DP(RINT "[WINSTART:%"Q"] input bytes %u offset %"Q"\n",
3414 stream->current_window, stream->avail_in, 3414 stream->current_window, stream->avail_in,
3415 stream->total_in)); 3415 stream->total_in));
3416 return XD3_WINSTART; 3416 return XD3_WINSTART;
@@ -3551,7 +3551,7 @@ xd3_encode_input (xd3_stream *stream)
3551 stream->total_in += (xoff_t) stream->avail_in; 3551 stream->total_in += (xoff_t) stream->avail_in;
3552 stream->enc_state = ENC_POSTWIN; 3552 stream->enc_state = ENC_POSTWIN;
3553 3553
3554 IF_DEBUG2 (DP(RINT "[WINFINISH:%"Q"u] in=%"Q"u\n", 3554 IF_DEBUG2 (DP(RINT "[WINFINISH:%"Q"] in=%"Q"\n",
3555 stream->current_window, 3555 stream->current_window,
3556 stream->total_in)); 3556 stream->total_in));
3557 return XD3_WINFINISH; 3557 return XD3_WINFINISH;
@@ -4002,13 +4002,13 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4002 * back further than the LRU cache maintaining FIFO discipline, (to 4002 * back further than the LRU cache maintaining FIFO discipline, (to
4003 * avoid seeking). */ 4003 * avoid seeking). */
4004 frontier_pos = stream->src->frontier_blkno * stream->src->blksize; 4004 frontier_pos = stream->src->frontier_blkno * stream->src->blksize;
4005 IF_DEBUG2(DP(RINT "[match_setup] frontier_pos %"Q"u, srcpos %"Q"u, " 4005 IF_DEBUG2(DP(RINT "[match_setup] frontier_pos %"Q", srcpos %"Q", "
4006 "src->max_winsize %"Q"u\n", 4006 "src->max_winsize %"Q"\n",
4007 frontier_pos, srcpos, stream->src->max_winsize)); 4007 frontier_pos, srcpos, stream->src->max_winsize));
4008 if (srcpos < frontier_pos && 4008 if (srcpos < frontier_pos &&
4009 frontier_pos - srcpos > stream->src->max_winsize) { 4009 frontier_pos - srcpos > stream->src->max_winsize) {
4010 IF_DEBUG1(DP(RINT "[match_setup] rejected due to src->max_winsize " 4010 IF_DEBUG1(DP(RINT "[match_setup] rejected due to src->max_winsize "
4011 "distance eof=%"Q"u srcpos=%"Q"u maxsz=%"Q"u\n", 4011 "distance eof=%"Q" srcpos=%"Q" maxsz=%"Q"\n",
4012 xd3_source_eof (stream->src), 4012 xd3_source_eof (stream->src),
4013 srcpos, stream->src->max_winsize)); 4013 srcpos, stream->src->max_winsize));
4014 goto bad; 4014 goto bad;
@@ -4065,7 +4065,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4065 } 4065 }
4066 4066
4067 IF_DEBUG2(DP(RINT 4067 IF_DEBUG2(DP(RINT
4068 "[match_setup] srcpos %"Q"u (tgtpos %"Q"u) " 4068 "[match_setup] srcpos %"Q" (tgtpos %"Q") "
4069 "unrestricted maxback %u maxfwd %u\n", 4069 "unrestricted maxback %u maxfwd %u\n",
4070 srcpos, 4070 srcpos,
4071 stream->total_in + stream->input_position, 4071 stream->total_in + stream->input_position,
@@ -4101,7 +4101,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4101 } 4101 }
4102 4102
4103 IF_DEBUG1(DP(RINT 4103 IF_DEBUG1(DP(RINT
4104 "[match_setup] srcpos %"Q"u (tgtpos %"Q"u) " 4104 "[match_setup] srcpos %"Q" (tgtpos %"Q") "
4105 "restricted maxback %u maxfwd %u\n", 4105 "restricted maxback %u maxfwd %u\n",
4106 srcpos, 4106 srcpos,
4107 stream->total_in + stream->input_position, 4107 stream->total_in + stream->input_position,
@@ -4180,7 +4180,7 @@ xd3_source_extend_match (xd3_stream *stream)
4180 usize_t tryrem; /* tryrem is the number of matchable bytes */ 4180 usize_t tryrem; /* tryrem is the number of matchable bytes */
4181 usize_t matched; 4181 usize_t matched;
4182 4182
4183 IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n", 4183 IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"\n",
4184 stream->match_srcpos)); 4184 stream->match_srcpos));
4185 4185
4186 XD3_ASSERT (src != NULL); 4186 XD3_ASSERT (src != NULL);
@@ -4218,7 +4218,7 @@ xd3_source_extend_match (xd3_stream *stream)
4218 4218
4219 tryrem = min (tryoff, stream->match_maxback - stream->match_back); 4219 tryrem = min (tryoff, stream->match_maxback - stream->match_back);
4220 4220
4221 IF_DEBUG2(DP(RINT "[maxback] maxback %u trysrc %"Q"u/%u tgt %u tryrem %u\n", 4221 IF_DEBUG2(DP(RINT "[maxback] maxback %u trysrc %"Q"/%u tgt %u tryrem %u\n",
4222 stream->match_maxback, tryblk, tryoff, streamoff, tryrem)); 4222 stream->match_maxback, tryblk, tryoff, streamoff, tryrem));
4223 4223
4224 /* TODO: This code can be optimized similar to xd3_match_forward() */ 4224 /* TODO: This code can be optimized similar to xd3_match_forward() */
@@ -4339,7 +4339,7 @@ xd3_source_extend_match (xd3_stream *stream)
4339 4339
4340 IF_DEBUG2 ({ 4340 IF_DEBUG2 ({
4341 static int x = 0; 4341 static int x = 0;
4342 DP(RINT "[source match:%d] <inp %"Q"u %"Q"u> <src %"Q"u %"Q"u> (%s) [ %u bytes ]\n", 4342 DP(RINT "[source match:%d] <inp %"Q" %"Q"> <src %"Q" %"Q"> (%s) [ %u bytes ]\n",
4343 x++, 4343 x++,
4344 stream->total_in + target_position, 4344 stream->total_in + target_position,
4345 stream->total_in + target_position + match_length, 4345 stream->total_in + target_position + match_length,
@@ -4666,13 +4666,13 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point)
4666 ret = XD3_INTERNAL; 4666 ret = XD3_INTERNAL;
4667 } 4667 }
4668 IF_DEBUG1 (DP(RINT 4668 IF_DEBUG1 (DP(RINT
4669 "[srcwin_move_point] async getblk return for %"Q"u\n", 4669 "[srcwin_move_point] async getblk return for %"Q"\n",
4670 blkno)); 4670 blkno));
4671 return ret; 4671 return ret;
4672 } 4672 }
4673 4673
4674 IF_DEBUG1 (DP(RINT 4674 IF_DEBUG1 (DP(RINT
4675 "[srcwin_move_point] T=%"Q"u{%"Q"u} S=%"Q"u EOF=%"Q"u %s\n", 4675 "[srcwin_move_point] T=%"Q"{%"Q"} S=%"Q" EOF=%"Q" %s\n",
4676 stream->total_in + stream->input_position, 4676 stream->total_in + stream->input_position,
4677 logical_input_cksum_pos, 4677 logical_input_cksum_pos,
4678 stream->srcwin_cksum_pos, 4678 stream->srcwin_cksum_pos,
@@ -4720,8 +4720,8 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point)
4720 } 4720 }
4721 4721
4722 IF_DEBUG1 (DP(RINT 4722 IF_DEBUG1 (DP(RINT
4723 "[srcwin_move_point] exited loop T=%"Q"u{%"Q"u} " 4723 "[srcwin_move_point] exited loop T=%"Q"{%"Q"} "
4724 "S=%"Q"u EOF=%"Q"u %s\n", 4724 "S=%"Q" EOF=%"Q" %s\n",
4725 stream->total_in + stream->input_position, 4725 stream->total_in + stream->input_position,
4726 logical_input_cksum_pos, 4726 logical_input_cksum_pos,
4727 stream->srcwin_cksum_pos, 4727 stream->srcwin_cksum_pos,
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index a643526..d8ea1ab 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -17,7 +17,7 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20/* To know more about Xdelta, start by reading xdelta3.c. If you are 20/* To learn more about Xdelta, start by reading xdelta3.c. If you are
21 * ready to use the API, continue reading here. There are two 21 * ready to use the API, continue reading here. There are two
22 * interfaces -- xd3_encode_input and xd3_decode_input -- plus a dozen 22 * interfaces -- xd3_encode_input and xd3_decode_input -- plus a dozen
23 * or so related calls. This interface is styled after Zlib. */ 23 * or so related calls. This interface is styled after Zlib. */
@@ -87,8 +87,7 @@
87#define XD3_DEFAULT_SPREVSZ (1U<<18) 87#define XD3_DEFAULT_SPREVSZ (1U<<18)
88#endif 88#endif
89 89
90/* The default compression level 90/* The default compression level */
91 */
92#ifndef XD3_DEFAULT_LEVEL 91#ifndef XD3_DEFAULT_LEVEL
93#define XD3_DEFAULT_LEVEL 3 92#define XD3_DEFAULT_LEVEL 3
94#endif 93#endif
@@ -101,6 +100,12 @@
101#define XD3_USE_LARGEFILE64 1 100#define XD3_USE_LARGEFILE64 1
102#endif 101#endif
103 102
103/* The default source window size is limited to 2GB unless
104 * XD3_USE_LARGEWINDOW64 is defined to 1. */
105#ifndef XD3_USE_LARGEWINDOW64
106#define XD3_USE_LARGEWINDOW64 0
107#endif
108
104/* Sizes and addresses within VCDIFF windows are represented as usize_t 109/* Sizes and addresses within VCDIFF windows are represented as usize_t
105 * 110 *
106 * For source-file offsets and total file sizes, total input and 111 * For source-file offsets and total file sizes, total input and
@@ -109,6 +114,8 @@
109 * the 32bit boundary [xdelta3-test.h]). 114 * the 32bit boundary [xdelta3-test.h]).
110 */ 115 */
111#ifndef _WIN32 116#ifndef _WIN32
117#define __STDC_FORMAT_MACROS
118#include <inttypes.h>
112#include <stdint.h> 119#include <stdint.h>
113#else 120#else
114#define WIN32_LEAN_AND_MEAN 121#define WIN32_LEAN_AND_MEAN
@@ -142,8 +149,6 @@ typedef ULONGLONG uint64_t;
142#endif 149#endif
143#endif 150#endif
144 151
145typedef uint32_t usize_t;
146
147#if XD3_USE_LARGEFILE64 152#if XD3_USE_LARGEFILE64
148#define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops, ... ? */ 153#define __USE_FILE_OFFSET64 1 /* GLIBC: for 64bit fileops, ... ? */
149#ifndef _LARGEFILE_SOURCE 154#ifndef _LARGEFILE_SOURCE
@@ -153,23 +158,43 @@ typedef uint32_t usize_t;
153#define _FILE_OFFSET_BITS 64 158#define _FILE_OFFSET_BITS 64
154#endif 159#endif
155 160
156typedef uint64_t xoff_t;
157#define SIZEOF_XOFF_T 8 161#define SIZEOF_XOFF_T 8
158#define SIZEOF_USIZE_T 4 162typedef uint64_t xoff_t;
159#ifndef WIN32 163
160#if SIZEOF_SIZE_T == 8 164#ifndef _WIN32
161#define Q "z" 165#define Q PRIu64
162#else 166//#define Qd PRId64
163#define Q "ll" 167#else /* _WIN32 */
164#endif 168#define Q "I64u"
165#else 169//#define Qd "I64d"
166#define Q "I64"
167#endif 170#endif
168#else 171
169typedef uint32_t xoff_t; 172#else /* XD3_USE_LARGEFILE64 */
173
170#define SIZEOF_XOFF_T 4 174#define SIZEOF_XOFF_T 4
175typedef uint32_t xoff_t;
176
177#define Q "u"
178//#define Qd "d"
179
180#endif /* XD3_USE_LARGEFILE64 */
181
182#if XD3_USE_LARGEWINDOW64
183
184#if !XD3_USE_LARGEFILE64
185#error "Invalid configuration"
186#endif
187
188#define SIZEOF_USIZE_T 8
189typedef uint64_t usize_t;
190
191#define Z Q
192#else /* XD3_USE_LARGEWINDOW64 */
193
171#define SIZEOF_USIZE_T 4 194#define SIZEOF_USIZE_T 4
172#define Q 195typedef uint32_t usize_t;
196
197#define Z "u"
173#endif 198#endif
174 199
175#define USE_UINT32 (SIZEOF_USIZE_T == 4 || \ 200#define USE_UINT32 (SIZEOF_USIZE_T == 4 || \
@@ -302,9 +327,12 @@ typedef int (xd3_comp_table_func) (xd3_stream *stream,
302 327
303 328
304#if XD3_DEBUG 329#if XD3_DEBUG
305#define XD3_ASSERT(x) \ 330#define XD3_ASSERT(x) \
306 do { if (! (x)) { DP(RINT "%s:%d: XD3 assertion failed: %s\n", __FILE__, __LINE__, #x); \ 331 do { \
307 abort (); } } while (0) 332 if (! (x)) { \
333 DP(RINT "%s:%d: XD3 assertion failed: %s\n", \
334 __FILE__, __LINE__, #x); \
335 abort (); } } while (0)
308#else 336#else
309#define XD3_ASSERT(x) (void)0 337#define XD3_ASSERT(x) (void)0
310#endif /* XD3_DEBUG */ 338#endif /* XD3_DEBUG */
@@ -556,9 +584,9 @@ struct _xd3_dinst
556/* the decoded form of a single (half) instruction. */ 584/* the decoded form of a single (half) instruction. */
557struct _xd3_hinst 585struct _xd3_hinst
558{ 586{
559 uint8_t type; 587 uint8_t type;
560 uint32_t size; /* TODO: why decode breaks if this is usize_t? */ 588 usize_t size;
561 uint32_t addr; /* TODO: why decode breaks if this is usize_t? */ 589 usize_t addr;
562}; 590};
563 591
564/* the form of a whole-file instruction */ 592/* the form of a whole-file instruction */
@@ -585,7 +613,7 @@ struct _xd3_desect
585{ 613{
586 const uint8_t *buf; 614 const uint8_t *buf;
587 const uint8_t *buf_max; 615 const uint8_t *buf_max;
588 uint32_t size; /* TODO: why decode breaks if this is usize_t? */ 616 usize_t size;
589 usize_t pos; 617 usize_t pos;
590 618
591 /* used in xdelta3-decode.h */ 619 /* used in xdelta3-decode.h */
@@ -898,13 +926,11 @@ struct _xd3_stream
898 926
899 usize_t dec_secondid; /* Optional secondary compressor ID. */ 927 usize_t dec_secondid; /* Optional secondary compressor ID. */
900 928
901 /* TODO: why decode breaks if this is usize_t? */ 929 usize_t dec_codetblsz; /* Optional code table: length. */
902 uint32_t dec_codetblsz; /* Optional code table: length. */
903 uint8_t *dec_codetbl; /* Optional code table: storage. */ 930 uint8_t *dec_codetbl; /* Optional code table: storage. */
904 usize_t dec_codetblbytes; /* Optional code table: position. */ 931 usize_t dec_codetblbytes; /* Optional code table: position. */
905 932
906 /* TODO: why decode breaks if this is usize_t? */ 933 usize_t dec_appheadsz; /* Optional application header:
907 uint32_t dec_appheadsz; /* Optional application header:
908 size. */ 934 size. */
909 uint8_t *dec_appheader; /* Optional application header: 935 uint8_t *dec_appheader; /* Optional application header:
910 storage */ 936 storage */
@@ -915,15 +941,12 @@ struct _xd3_stream
915 uint8_t dec_cksum[4]; /* Optional checksum: storage. */ 941 uint8_t dec_cksum[4]; /* Optional checksum: storage. */
916 uint32_t dec_adler32; /* Optional checksum: value. */ 942 uint32_t dec_adler32; /* Optional checksum: value. */
917 943
918 /* TODO: why decode breaks if this is usize_t? */ 944 usize_t dec_cpylen; /* length of copy window
919 uint32_t dec_cpylen; /* length of copy window
920 (VCD_SOURCE or VCD_TARGET) */ 945 (VCD_SOURCE or VCD_TARGET) */
921 xoff_t dec_cpyoff; /* offset of copy window 946 xoff_t dec_cpyoff; /* offset of copy window
922 (VCD_SOURCE or VCD_TARGET) */ 947 (VCD_SOURCE or VCD_TARGET) */
923 /* TODO: why decode breaks if this is usize_t? */ 948 usize_t dec_enclen; /* length of delta encoding */
924 uint32_t dec_enclen; /* length of delta encoding */ 949 usize_t dec_tgtlen; /* length of target window */
925 /* TODO: why decode breaks if this is usize_t? */
926 uint32_t dec_tgtlen; /* length of target window */
927 950
928#if USE_UINT64 951#if USE_UINT64
929 uint64_t dec_64part; /* part of a decoded uint64_t */ 952 uint64_t dec_64part; /* part of a decoded uint64_t */