summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2009-11-03 01:50:13 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2009-11-03 01:50:13 +0000
commit7f7ac45b750fe90bc0572c1a53981910d24b878a (patch)
treefedb4169e6e2e4babf3e59bb82684e6d762f90ab /xdelta3
parent9c3c0e573dd63bd1a0345d38f46594293d58c9d2 (diff)
Fixes for issue 94.
Diffstat (limited to 'xdelta3')
-rw-r--r--xdelta3/xdelta3-decode.h3
-rw-r--r--xdelta3/xdelta3.c30
-rw-r--r--xdelta3/xdelta3.h15
3 files changed, 23 insertions, 25 deletions
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h
index ff5e999..542b6aa 100644
--- a/xdelta3/xdelta3-decode.h
+++ b/xdelta3/xdelta3-decode.h
@@ -904,7 +904,8 @@ xd3_decode_input (xd3_stream *stream)
904 } 904 }
905 } 905 }
906 906
907 stream->dec_hdrsize = stream->total_in; 907 /* xoff_t -> usize_t is safe because this is the first block. */
908 stream->dec_hdrsize = (usize_t) stream->total_in;
908 stream->dec_state = DEC_WININD; 909 stream->dec_state = DEC_WININD;
909 910
910 case DEC_WININD: 911 case DEC_WININD:
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 868c2ca..435e8d8 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -2583,17 +2583,16 @@ xd3_set_source (xd3_stream *stream,
2583 2583
2584 // If src->blksize is a power-of-two, xd3_blksize_div() will use 2584 // If src->blksize is a power-of-two, xd3_blksize_div() will use
2585 // shift and mask rather than divide. Check that here. 2585 // shift and mask rather than divide. Check that here.
2586 if (xd3_check_pow2 (src->blksize, &shiftby) == 0) 2586 if (!xd3_check_pow2 (src->blksize, &shiftby) == 0)
2587 {
2588 src->shiftby = shiftby;
2589 src->maskby = (1 << shiftby) - 1;
2590 }
2591 else
2592 { 2587 {
2588 int check;
2593 src->blksize = xd3_pow2_roundup(src->blksize); 2589 src->blksize = xd3_pow2_roundup(src->blksize);
2594 xd3_check_pow2 (src->blksize, &shiftby); 2590 check = xd3_check_pow2 (src->blksize, &shiftby);
2591 XD3_ASSERT (check == 0);
2595 } 2592 }
2596 2593
2594 src->shiftby = shiftby;
2595 src->maskby = (1 << shiftby) - 1;
2597 return 0; 2596 return 0;
2598} 2597}
2599 2598
@@ -2777,14 +2776,14 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst)
2777 XD3_ASSERT (inst->addr + inst->size <= src->srcbase + src->srclen); 2776 XD3_ASSERT (inst->addr + inst->size <= src->srcbase + src->srclen);
2778 addr = (inst->addr - src->srcbase); 2777 addr = (inst->addr - src->srcbase);
2779 stream->n_scpy += 1; 2778 stream->n_scpy += 1;
2780 stream->l_scpy += inst->size; 2779 stream->l_scpy += (xoff_t) inst->size;
2781 } 2780 }
2782 else 2781 else
2783 { 2782 {
2784 /* with source window: target copy address is offset by taroff. */ 2783 /* with source window: target copy address is offset by taroff. */
2785 addr = stream->taroff + (usize_t) inst->addr; 2784 addr = stream->taroff + (usize_t) inst->addr;
2786 stream->n_tcpy += 1; 2785 stream->n_tcpy += 1;
2787 stream->l_tcpy += inst->size; 2786 stream->l_tcpy += (xoff_t) inst->size;
2788 } 2787 }
2789 } 2788 }
2790 else 2789 else
@@ -3483,10 +3482,11 @@ xd3_emit_hdr (xd3_stream *stream)
3483 a32 = stream->recode_adler32; 3482 a32 = stream->recode_adler32;
3484 } 3483 }
3485 3484
3486 send[0] = (a32 >> 24); 3485 /* Four bytes. */
3487 send[1] = (a32 >> 16); 3486 send[0] = (uint8_t) (a32 >> 24);
3488 send[2] = (a32 >> 8); 3487 send[1] = (uint8_t) (a32 >> 16);
3489 send[3] = (a32 & 0xff); 3488 send[2] = (uint8_t) (a32 >> 8);
3489 send[3] = (uint8_t) (a32 & 0x000000FFU);
3490 3490
3491 if ((ret = xd3_emit_bytes (stream, & HDR_TAIL (stream), send, 4))) 3491 if ((ret = xd3_emit_bytes (stream, & HDR_TAIL (stream), send, 4)))
3492 { 3492 {
@@ -4374,7 +4374,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4374 * src->size/srcpos values and take the min. */ 4374 * src->size/srcpos values and take the min. */
4375 if (srcpos < (xoff_t) stream->match_maxback) 4375 if (srcpos < (xoff_t) stream->match_maxback)
4376 { 4376 {
4377 stream->match_maxback = srcpos; 4377 stream->match_maxback = (usize_t) srcpos;
4378 } 4378 }
4379 4379
4380 if (stream->src->eof_known) 4380 if (stream->src->eof_known)
@@ -4383,7 +4383,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4383 4383
4384 if (srcavail < (xoff_t) stream->match_maxfwd) 4384 if (srcavail < (xoff_t) stream->match_maxfwd)
4385 { 4385 {
4386 stream->match_maxfwd = srcavail; 4386 stream->match_maxfwd = (usize_t) srcavail;
4387 } 4387 }
4388 } 4388 }
4389 4389
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index ac5720f..c2741dd 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -1289,7 +1289,7 @@ void xd3_set_flags (xd3_stream *stream, int flags)
1289} 1289}
1290 1290
1291/* Gives some extra information about the latest library error, if any 1291/* Gives some extra information about the latest library error, if any
1292 is known. */ 1292 * is known. */
1293static inline 1293static inline
1294const char* xd3_errstring (xd3_stream *stream) 1294const char* xd3_errstring (xd3_stream *stream)
1295{ 1295{
@@ -1297,19 +1297,16 @@ const char* xd3_errstring (xd3_stream *stream)
1297} 1297}
1298 1298
1299 1299
1300/* 64-bit divisions are expensive. on a 32bit platform, these show in 1300/* 64-bit divisions are expensive, which is why we require a power-of-2
1301 * a profile as __udivdi3(). these are all the xoff_t divisions: */ 1301 * block size. To relax this restriction is relatively easy, see the history
1302 * for this method. gcc users should not see __udivdi3() in xd3_ profiles. */
1302static inline 1303static inline
1303void xd3_blksize_div (const xoff_t offset, 1304void xd3_blksize_div (const xoff_t offset,
1304 const xd3_source *source, 1305 const xd3_source *source,
1305 xoff_t *blkno, 1306 xoff_t *blkno,
1306 usize_t *blkoff) { 1307 usize_t *blkoff) {
1307 *blkno = source->maskby ? 1308 *blkno = (xoff_t) (offset >> source->shiftby);
1308 (offset >> source->shiftby) : 1309 *blkoff = (usize_t) (offset & source->maskby);
1309 (offset / source->blksize);
1310 *blkoff = source->maskby ?
1311 (offset & source->maskby) :
1312 (offset - *blkno * source->blksize);
1313} 1310}
1314 1311
1315#endif /* _XDELTA3_H_ */ 1312#endif /* _XDELTA3_H_ */