diff options
-rw-r--r-- | xdelta3/Makefile.am | 3 | ||||
-rw-r--r-- | xdelta3/xdelta3-blkcache.h | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3-djw.h | 8 | ||||
-rw-r--r-- | xdelta3/xdelta3-fgk.h | 12 | ||||
-rw-r--r-- | xdelta3/xdelta3-hash.h | 6 | ||||
-rw-r--r-- | xdelta3/xdelta3-internal.h | 4 | ||||
-rw-r--r-- | xdelta3/xdelta3-list.h | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3-lzma.h | 3 | ||||
-rw-r--r-- | xdelta3/xdelta3-main.h | 4 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 110 | ||||
-rw-r--r-- | xdelta3/xdelta3.h | 8 |
11 files changed, 90 insertions, 72 deletions
diff --git a/xdelta3/Makefile.am b/xdelta3/Makefile.am index 94fce8a..3907351 100644 --- a/xdelta3/Makefile.am +++ b/xdelta3/Makefile.am | |||
@@ -38,7 +38,8 @@ 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. |
40 | WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \ | 40 | WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \ |
41 | -Wextra -Wno-unused-parameter | 41 | -Wextra -Wno-unused-parameter -Wconversion |
42 | |||
42 | 43 | ||
43 | C_WFLAGS = $(WFLAGS) -pedantic -std=c99 | 44 | C_WFLAGS = $(WFLAGS) -pedantic -std=c99 |
44 | CXX_WFLAGS = $(WFLAGS) | 45 | CXX_WFLAGS = $(WFLAGS) |
diff --git a/xdelta3/xdelta3-blkcache.h b/xdelta3/xdelta3-blkcache.h index 82d720e..e73a2ab 100644 --- a/xdelta3/xdelta3-blkcache.h +++ b/xdelta3/xdelta3-blkcache.h | |||
@@ -129,7 +129,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, | |||
129 | /* Note: The API requires a power-of-two blocksize and srcwinsz | 129 | /* Note: The API requires a power-of-two blocksize and srcwinsz |
130 | * (-B). The logic here will use a single block if the entire file | 130 | * (-B). The logic here will use a single block if the entire file |
131 | * is known to fit into srcwinsz. */ | 131 | * is known to fit into srcwinsz. */ |
132 | option_srcwinsz = xd3_pow2_roundup (option_srcwinsz); | 132 | option_srcwinsz = xd3_xoff_roundup (option_srcwinsz); |
133 | 133 | ||
134 | /* Though called "lru", it is not LRU-specific. We always allocate | 134 | /* Though called "lru", it is not LRU-specific. We always allocate |
135 | * a maximum number of source block buffers. If the entire file | 135 | * a maximum number of source block buffers. If the entire file |
diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h index 422e06a..cba061e 100644 --- a/xdelta3/xdelta3-djw.h +++ b/xdelta3/xdelta3-djw.h | |||
@@ -343,7 +343,7 @@ static inline void | |||
343 | djw_update_1_2 (int *mtf_run, usize_t *mtf_i, | 343 | djw_update_1_2 (int *mtf_run, usize_t *mtf_i, |
344 | uint8_t *mtfsym, djw_weight *freq) | 344 | uint8_t *mtfsym, djw_weight *freq) |
345 | { | 345 | { |
346 | int code; | 346 | uint8_t code; |
347 | 347 | ||
348 | do | 348 | do |
349 | { | 349 | { |
@@ -395,10 +395,10 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t | |||
395 | usize_t heap_last; /* Index of the last _valid_ heap entry. */ | 395 | usize_t heap_last; /* Index of the last _valid_ heap entry. */ |
396 | usize_t ents_size; /* Number of entries, including 0th fake entry */ | 396 | usize_t ents_size; /* Number of entries, including 0th fake entry */ |
397 | usize_t overflow; /* Number of code lengths that overflow */ | 397 | usize_t overflow; /* Number of code lengths that overflow */ |
398 | uint32_t total_bits; | 398 | usize_t total_bits; |
399 | usize_t i; | 399 | usize_t i; |
400 | 400 | ||
401 | IF_DEBUG (uint32_t first_bits = 0); | 401 | IF_DEBUG (usize_t first_bits = 0); |
402 | 402 | ||
403 | /* Insert real symbol frequences. */ | 403 | /* Insert real symbol frequences. */ |
404 | for (i = 0; i < asize; i += 1) | 404 | for (i = 0; i < asize; i += 1) |
@@ -444,7 +444,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t | |||
444 | if (heap_last == 1) | 444 | if (heap_last == 1) |
445 | { | 445 | { |
446 | /* Pick either the first or last symbol. */ | 446 | /* Pick either the first or last symbol. */ |
447 | int s = freq[0] ? asize-1 : 0; | 447 | usize_t s = freq[0] ? asize-1 : 0; |
448 | ents[s+1].freq = 1; | 448 | ents[s+1].freq = 1; |
449 | goto again; | 449 | goto again; |
450 | } | 450 | } |
diff --git a/xdelta3/xdelta3-fgk.h b/xdelta3/xdelta3-fgk.h index 7011500..81d5e7e 100644 --- a/xdelta3/xdelta3-fgk.h +++ b/xdelta3/xdelta3-fgk.h | |||
@@ -109,7 +109,7 @@ static fgk_stream* fgk_alloc (xd3_stream *stream /*, usize_t alpha | |||
109 | static int fgk_init (xd3_stream *stream, | 109 | static int fgk_init (xd3_stream *stream, |
110 | fgk_stream *h, | 110 | fgk_stream *h, |
111 | int is_encode); | 111 | int is_encode); |
112 | static int fgk_encode_data (fgk_stream *h, | 112 | static usize_t fgk_encode_data (fgk_stream *h, |
113 | usize_t n); | 113 | usize_t n); |
114 | static inline fgk_bit fgk_get_encoded_bit (fgk_stream *h); | 114 | static inline fgk_bit fgk_get_encoded_bit (fgk_stream *h); |
115 | 115 | ||
@@ -125,7 +125,7 @@ static int xd3_encode_fgk (xd3_stream *stream, | |||
125 | 125 | ||
126 | static inline int fgk_decode_bit (fgk_stream *h, | 126 | static inline int fgk_decode_bit (fgk_stream *h, |
127 | fgk_bit b); | 127 | fgk_bit b); |
128 | static int fgk_decode_data (fgk_stream *h); | 128 | static usize_t fgk_decode_data (fgk_stream *h); |
129 | static void fgk_destroy (xd3_stream *stream, | 129 | static void fgk_destroy (xd3_stream *stream, |
130 | fgk_stream *h); | 130 | fgk_stream *h); |
131 | 131 | ||
@@ -234,7 +234,7 @@ static void fgk_swap_ptrs(fgk_node **one, fgk_node **two) | |||
234 | 234 | ||
235 | /* Takes huffman transmitter h and n, the nth elt in the alphabet, and | 235 | /* Takes huffman transmitter h and n, the nth elt in the alphabet, and |
236 | * returns the number of required to encode n. */ | 236 | * returns the number of required to encode n. */ |
237 | static int fgk_encode_data (fgk_stream* h, usize_t n) | 237 | static usize_t fgk_encode_data (fgk_stream* h, usize_t n) |
238 | { | 238 | { |
239 | fgk_node *target_ptr = h->alphabet + n; | 239 | fgk_node *target_ptr = h->alphabet + n; |
240 | 240 | ||
@@ -249,8 +249,8 @@ static int fgk_encode_data (fgk_stream* h, usize_t n) | |||
249 | * is not neccesary to encode these bits. */ | 249 | * is not neccesary to encode these bits. */ |
250 | if (IS_ADAPTIVE && target_ptr->weight == 0) | 250 | if (IS_ADAPTIVE && target_ptr->weight == 0) |
251 | { | 251 | { |
252 | unsigned int where, shift; | 252 | usize_t where, shift; |
253 | int bits; | 253 | usize_t bits; |
254 | 254 | ||
255 | where = fgk_find_nth_zero(h, n); | 255 | where = fgk_find_nth_zero(h, n); |
256 | shift = 1; | 256 | shift = 1; |
@@ -734,7 +734,7 @@ static usize_t fgk_nth_zero (fgk_stream* h, usize_t n) | |||
734 | * alphabet otherwise this returns 0, indicating more bits are | 734 | * alphabet otherwise this returns 0, indicating more bits are |
735 | * required. | 735 | * required. |
736 | */ | 736 | */ |
737 | static int fgk_decode_data (fgk_stream* h) | 737 | static usize_t fgk_decode_data (fgk_stream* h) |
738 | { | 738 | { |
739 | usize_t elt = (usize_t)(h->decode_ptr - h->alphabet); | 739 | usize_t elt = (usize_t)(h->decode_ptr - h->alphabet); |
740 | 740 | ||
diff --git a/xdelta3/xdelta3-hash.h b/xdelta3/xdelta3-hash.h index e359436..600e0d6 100644 --- a/xdelta3/xdelta3-hash.h +++ b/xdelta3/xdelta3-hash.h | |||
@@ -136,8 +136,8 @@ xd3_lcksum (const uint8_t *seg, const usize_t ln) | |||
136 | static usize_t | 136 | static usize_t |
137 | xd3_size_log2 (usize_t slots) | 137 | xd3_size_log2 (usize_t slots) |
138 | { | 138 | { |
139 | int bits = 28; /* This should not be an unreasonable limit. */ | 139 | usize_t bits = 31; |
140 | int i; | 140 | usize_t i; |
141 | 141 | ||
142 | for (i = 3; i <= bits; i += 1) | 142 | for (i = 3; i <= bits; i += 1) |
143 | { | 143 | { |
@@ -158,7 +158,7 @@ xd3_size_hashtable (xd3_stream *stream, | |||
158 | usize_t slots, | 158 | usize_t slots, |
159 | xd3_hash_cfg *cfg) | 159 | xd3_hash_cfg *cfg) |
160 | { | 160 | { |
161 | int bits = xd3_size_log2 (slots); | 161 | usize_t bits = xd3_size_log2 (slots); |
162 | 162 | ||
163 | /* TODO: there's a 32-bit assumption here */ | 163 | /* TODO: there's a 32-bit assumption here */ |
164 | cfg->size = (1 << bits); | 164 | cfg->size = (1 << bits); |
diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h index 35de56b..b586e06 100644 --- a/xdelta3/xdelta3-internal.h +++ b/xdelta3/xdelta3-internal.h | |||
@@ -47,7 +47,7 @@ uint32_t xd3_large_cksum_update (uint32_t cksum, | |||
47 | const uint8_t *base, | 47 | const uint8_t *base, |
48 | usize_t look); | 48 | usize_t look); |
49 | int xd3_encode_init_full (xd3_stream *stream); | 49 | int xd3_encode_init_full (xd3_stream *stream); |
50 | size_t xd3_pow2_roundup (size_t x); | 50 | usize_t xd3_pow2_roundup (usize_t x); |
51 | int xd3_process_stream (int is_encode, | 51 | int xd3_process_stream (int is_encode, |
52 | xd3_stream *stream, | 52 | xd3_stream *stream, |
53 | int (*func) (xd3_stream *), | 53 | int (*func) (xd3_stream *), |
@@ -136,7 +136,7 @@ typedef struct { | |||
136 | #endif | 136 | #endif |
137 | 137 | ||
138 | /* Underlying xprintf() */ | 138 | /* Underlying xprintf() */ |
139 | int xsnprintf_func (char *str, int n, const char *fmt, ...) | 139 | int xsnprintf_func (char *str, size_t n, const char *fmt, ...) |
140 | PRINTF_ATTRIBUTE(3,4); | 140 | PRINTF_ATTRIBUTE(3,4); |
141 | 141 | ||
142 | /* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */ | 142 | /* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */ |
diff --git a/xdelta3/xdelta3-list.h b/xdelta3/xdelta3-list.h index 6e3125f..2c8f3ef 100644 --- a/xdelta3/xdelta3-list.h +++ b/xdelta3/xdelta3-list.h | |||
@@ -115,7 +115,7 @@ static inline usize_t \ | |||
115 | LTYPE ## _length (LTYPE *l) \ | 115 | LTYPE ## _length (LTYPE *l) \ |
116 | { \ | 116 | { \ |
117 | LTYPE *p; \ | 117 | LTYPE *p; \ |
118 | int c = 0; \ | 118 | usize_t c = 0; \ |
119 | \ | 119 | \ |
120 | for (p = l->next; p != l; p = p->next) \ | 120 | for (p = l->next; p != l; p = p->next) \ |
121 | { \ | 121 | { \ |
diff --git a/xdelta3/xdelta3-lzma.h b/xdelta3/xdelta3-lzma.h index 5be8407..5f9f9c8 100644 --- a/xdelta3/xdelta3-lzma.h +++ b/xdelta3/xdelta3-lzma.h | |||
@@ -55,7 +55,8 @@ xd3_lzma_init (xd3_stream *stream, xd3_lzma_stream *sec, int is_encode) | |||
55 | 55 | ||
56 | if (is_encode) | 56 | if (is_encode) |
57 | { | 57 | { |
58 | int preset = (stream->flags & XD3_COMPLEVEL_MASK) >> XD3_COMPLEVEL_SHIFT; | 58 | uint32_t preset = |
59 | (stream->flags & XD3_COMPLEVEL_MASK) >> XD3_COMPLEVEL_SHIFT; | ||
59 | 60 | ||
60 | if (lzma_lzma_preset(&sec->options, preset)) | 61 | if (lzma_lzma_preset(&sec->options, preset)) |
61 | { | 62 | { |
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 018a697..108a71a 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h | |||
@@ -68,7 +68,7 @@ const char* xd3_mainerror(int err_num); | |||
68 | #include "xdelta3-internal.h" | 68 | #include "xdelta3-internal.h" |
69 | 69 | ||
70 | int | 70 | int |
71 | xsnprintf_func (char *str, int n, const char *fmt, ...) | 71 | xsnprintf_func (char *str, size_t n, const char *fmt, ...) |
72 | { | 72 | { |
73 | va_list a; | 73 | va_list a; |
74 | int ret; | 74 | int ret; |
@@ -3041,7 +3041,7 @@ main_input (xd3_cmd cmd, | |||
3041 | { | 3041 | { |
3042 | const char *s = option_smatch_config; | 3042 | const char *s = option_smatch_config; |
3043 | char *e; | 3043 | char *e; |
3044 | int values[XD3_SOFTCFG_VARCNT]; | 3044 | usize_t values[XD3_SOFTCFG_VARCNT]; |
3045 | int got; | 3045 | int got; |
3046 | 3046 | ||
3047 | config.smatch_cfg = XD3_SMATCH_SOFT; | 3047 | config.smatch_cfg = XD3_SMATCH_SOFT; |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 8513aac..c17a298 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -495,9 +495,9 @@ static int xd3_emit_bytes (xd3_stream *stream, | |||
495 | usize_t size); | 495 | usize_t size); |
496 | 496 | ||
497 | static int xd3_emit_double (xd3_stream *stream, xd3_rinst *first, | 497 | static int xd3_emit_double (xd3_stream *stream, xd3_rinst *first, |
498 | xd3_rinst *second, usize_t code); | 498 | xd3_rinst *second, uint8_t code); |
499 | static int xd3_emit_single (xd3_stream *stream, xd3_rinst *single, | 499 | static int xd3_emit_single (xd3_stream *stream, xd3_rinst *single, |
500 | usize_t code); | 500 | uint8_t code); |
501 | 501 | ||
502 | static usize_t xd3_sizeof_output (xd3_output *output); | 502 | static usize_t xd3_sizeof_output (xd3_output *output); |
503 | static void xd3_encode_reset (xd3_stream *stream); | 503 | static void xd3_encode_reset (xd3_stream *stream); |
@@ -619,7 +619,7 @@ const char* xd3_strerror (int ret) | |||
619 | 619 | ||
620 | struct _xd3_sec_type | 620 | struct _xd3_sec_type |
621 | { | 621 | { |
622 | int id; | 622 | uint8_t id; |
623 | const char *name; | 623 | const char *name; |
624 | xd3_secondary_flags flags; | 624 | xd3_secondary_flags flags; |
625 | 625 | ||
@@ -651,7 +651,7 @@ struct _xd3_sec_type | |||
651 | typedef struct _bit_state bit_state; | 651 | typedef struct _bit_state bit_state; |
652 | struct _bit_state | 652 | struct _bit_state |
653 | { | 653 | { |
654 | usize_t cur_byte; | 654 | uint8_t cur_byte; |
655 | usize_t cur_mask; | 655 | usize_t cur_mask; |
656 | }; | 656 | }; |
657 | 657 | ||
@@ -890,24 +890,32 @@ struct _xd3_code_table_desc | |||
890 | /* Assumes a single RUN instruction */ | 890 | /* Assumes a single RUN instruction */ |
891 | /* Assumes that MIN_MATCH is 4 */ | 891 | /* Assumes that MIN_MATCH is 4 */ |
892 | 892 | ||
893 | uint8_t add_sizes; /* Number of immediate-size single adds (default 17) */ | 893 | uint8_t add_sizes; /* Number of immediate-size single |
894 | adds (default 17) */ | ||
894 | uint8_t near_modes; /* Number of near copy modes (default 4) */ | 895 | uint8_t near_modes; /* Number of near copy modes (default 4) */ |
895 | uint8_t same_modes; /* Number of same copy modes (default 3) */ | 896 | uint8_t same_modes; /* Number of same copy modes (default 3) */ |
896 | uint8_t cpy_sizes; /* Number of immediate-size single copies (default 15) */ | 897 | uint8_t cpy_sizes; /* Number of immediate-size single |
897 | 898 | copies (default 15) */ | |
898 | uint8_t addcopy_add_max; /* Maximum add size for an add-copy double instruction, | 899 | |
899 | all modes (default 4) */ | 900 | uint8_t addcopy_add_max; /* Maximum add size for an add-copy |
900 | uint8_t addcopy_near_cpy_max; /* Maximum cpy size for an add-copy double instruction, | 901 | double instruction, all modes |
901 | up through VCD_NEAR modes (default 6) */ | 902 | (default 4) */ |
902 | uint8_t addcopy_same_cpy_max; /* Maximum cpy size for an add-copy double instruction, | 903 | uint8_t addcopy_near_cpy_max; /* Maximum cpy size for an add-copy |
903 | VCD_SAME modes (default 4) */ | 904 | double instruction, up through |
904 | 905 | VCD_NEAR modes (default 6) */ | |
905 | uint8_t copyadd_add_max; /* Maximum add size for a copy-add double instruction, | 906 | uint8_t addcopy_same_cpy_max; /* Maximum cpy size for an add-copy |
906 | all modes (default 1) */ | 907 | double instruction, VCD_SAME modes |
907 | uint8_t copyadd_near_cpy_max; /* Maximum cpy size for a copy-add double instruction, | 908 | (default 4) */ |
908 | up through VCD_NEAR modes (default 4) */ | 909 | |
909 | uint8_t copyadd_same_cpy_max; /* Maximum cpy size for a copy-add double instruction, | 910 | uint8_t copyadd_add_max; /* Maximum add size for a copy-add |
910 | VCD_SAME modes (default 4) */ | 911 | double instruction, all modes |
912 | (default 1) */ | ||
913 | uint8_t copyadd_near_cpy_max; /* Maximum cpy size for a copy-add | ||
914 | double instruction, up through | ||
915 | VCD_NEAR modes (default 4) */ | ||
916 | uint8_t copyadd_same_cpy_max; /* Maximum cpy size for a copy-add | ||
917 | double instruction, VCD_SAME modes | ||
918 | (default 4) */ | ||
911 | 919 | ||
912 | xd3_code_table_sizes addcopy_max_sizes[MAX_MODES]; | 920 | xd3_code_table_sizes addcopy_max_sizes[MAX_MODES]; |
913 | xd3_code_table_sizes copyadd_max_sizes[MAX_MODES]; | 921 | xd3_code_table_sizes copyadd_max_sizes[MAX_MODES]; |
@@ -929,16 +937,19 @@ static const xd3_code_table_desc __rfc3284_code_table_desc = { | |||
929 | 4, /* copy-add max cpy, same */ | 937 | 4, /* copy-add max cpy, same */ |
930 | 938 | ||
931 | /* addcopy */ | 939 | /* addcopy */ |
932 | { {6,163,3},{6,175,3},{6,187,3},{6,199,3},{6,211,3},{6,223,3},{4,235,1},{4,239,1},{4,243,1} }, | 940 | { {6,163,3},{6,175,3},{6,187,3},{6,199,3},{6,211,3},{6,223,3}, |
941 | {4,235,1},{4,239,1},{4,243,1} }, | ||
933 | /* copyadd */ | 942 | /* copyadd */ |
934 | { {4,247,1},{4,248,1},{4,249,1},{4,250,1},{4,251,1},{4,252,1},{4,253,1},{4,254,1},{4,255,1} }, | 943 | { {4,247,1},{4,248,1},{4,249,1},{4,250,1},{4,251,1},{4,252,1}, |
944 | {4,253,1},{4,254,1},{4,255,1} }, | ||
935 | }; | 945 | }; |
936 | 946 | ||
937 | /* Computes code table entries of TBL using the specified description. */ | 947 | /* Computes code table entries of TBL using the specified description. */ |
938 | static void | 948 | static void |
939 | xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) | 949 | xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) |
940 | { | 950 | { |
941 | usize_t size1, size2, mode; | 951 | uint8_t size1, size2; |
952 | uint8_t mode; | ||
942 | usize_t cpy_modes = 2 + desc->near_modes + desc->same_modes; | 953 | usize_t cpy_modes = 2 + desc->near_modes + desc->same_modes; |
943 | xd3_dinst *d = tbl; | 954 | xd3_dinst *d = tbl; |
944 | 955 | ||
@@ -955,7 +966,8 @@ xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) | |||
955 | { | 966 | { |
956 | (d++)->type1 = XD3_CPY + mode; | 967 | (d++)->type1 = XD3_CPY + mode; |
957 | 968 | ||
958 | for (size1 = MIN_MATCH; size1 < MIN_MATCH + desc->cpy_sizes; size1 += 1, d += 1) | 969 | for (size1 = MIN_MATCH; size1 < MIN_MATCH + desc->cpy_sizes; |
970 | size1 += 1, d += 1) | ||
959 | { | 971 | { |
960 | d->type1 = XD3_CPY + mode; | 972 | d->type1 = XD3_CPY + mode; |
961 | d->size1 = size1; | 973 | d->size1 = size1; |
@@ -1047,7 +1059,7 @@ xd3_choose_instruction (xd3_rinst *prev, xd3_rinst *inst) | |||
1047 | 1059 | ||
1048 | default: | 1060 | default: |
1049 | { | 1061 | { |
1050 | int mode = inst->type - XD3_CPY; | 1062 | uint8_t mode = inst->type - XD3_CPY; |
1051 | 1063 | ||
1052 | XD3_ASSERT (inst->type >= XD3_CPY && inst->type < 12); | 1064 | XD3_ASSERT (inst->type >= XD3_CPY && inst->type < 12); |
1053 | 1065 | ||
@@ -1064,8 +1076,9 @@ xd3_choose_instruction (xd3_rinst *prev, xd3_rinst *inst) | |||
1064 | if ( (inst->size <= 6) && | 1076 | if ( (inst->size <= 6) && |
1065 | (mode <= 5) ) | 1077 | (mode <= 5) ) |
1066 | { | 1078 | { |
1067 | prev->code2 = 163 + (mode * 12) + (3 * (prev->size - 1)) + (inst->size - 4); | 1079 | prev->code2 = (uint8_t)(163 + (mode * 12) + |
1068 | 1080 | (3 * (prev->size - 1)) + | |
1081 | (inst->size - 4)); | ||
1069 | XD3_ASSERT (prev->code2 <= 234); | 1082 | XD3_ASSERT (prev->code2 <= 234); |
1070 | } | 1083 | } |
1071 | else if ( (inst->size == 4) && | 1084 | else if ( (inst->size == 4) && |
@@ -1126,10 +1139,10 @@ xd3_check_pow2 (xoff_t value, usize_t *logof) | |||
1126 | return XD3_INTERNAL; | 1139 | return XD3_INTERNAL; |
1127 | } | 1140 | } |
1128 | 1141 | ||
1129 | size_t | 1142 | usize_t |
1130 | xd3_pow2_roundup (size_t x) | 1143 | xd3_pow2_roundup (usize_t x) |
1131 | { | 1144 | { |
1132 | size_t i = 1; | 1145 | usize_t i = 1; |
1133 | while (x > i) { | 1146 | while (x > i) { |
1134 | i <<= 1U; | 1147 | i <<= 1U; |
1135 | } | 1148 | } |
@@ -1161,7 +1174,8 @@ xd3_round_blksize (usize_t sz, usize_t blksz) | |||
1161 | ***********************************************************************/ | 1174 | ***********************************************************************/ |
1162 | 1175 | ||
1163 | #define A32_BASE 65521L /* Largest prime smaller than 2^16 */ | 1176 | #define A32_BASE 65521L /* Largest prime smaller than 2^16 */ |
1164 | #define A32_NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ | 1177 | #define A32_NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 |
1178 | + (n+1)(BASE-1) <= 2^32-1 */ | ||
1165 | 1179 | ||
1166 | #define A32_DO1(buf,i) {s1 += buf[i]; s2 += s1;} | 1180 | #define A32_DO1(buf,i) {s1 += buf[i]; s2 += s1;} |
1167 | #define A32_DO2(buf,i) A32_DO1(buf,i); A32_DO1(buf,i+1); | 1181 | #define A32_DO2(buf,i) A32_DO1(buf,i); A32_DO1(buf,i+1); |
@@ -1169,11 +1183,10 @@ xd3_round_blksize (usize_t sz, usize_t blksz) | |||
1169 | #define A32_DO8(buf,i) A32_DO4(buf,i); A32_DO4(buf,i+4); | 1183 | #define A32_DO8(buf,i) A32_DO4(buf,i); A32_DO4(buf,i+4); |
1170 | #define A32_DO16(buf) A32_DO8(buf,0); A32_DO8(buf,8); | 1184 | #define A32_DO16(buf) A32_DO8(buf,0); A32_DO8(buf,8); |
1171 | 1185 | ||
1172 | static unsigned long adler32 (unsigned long adler, const uint8_t *buf, | 1186 | static uint32_t adler32 (uint32_t adler, const uint8_t *buf, usize_t len) |
1173 | usize_t len) | ||
1174 | { | 1187 | { |
1175 | unsigned long s1 = adler & 0xffff; | 1188 | uint32_t s1 = adler & 0xffffU; |
1176 | unsigned long s2 = (adler >> 16) & 0xffff; | 1189 | uint32_t s2 = (adler >> 16) & 0xffffU; |
1177 | int k; | 1190 | int k; |
1178 | 1191 | ||
1179 | while (len > 0) | 1192 | while (len > 0) |
@@ -1556,7 +1569,8 @@ xd3_encode_address (xd3_stream *stream, | |||
1556 | uint8_t* mode) | 1569 | uint8_t* mode) |
1557 | { | 1570 | { |
1558 | usize_t d, bestd; | 1571 | usize_t d, bestd; |
1559 | usize_t i, bestm, ret; | 1572 | usize_t i, bestm; |
1573 | int ret; | ||
1560 | xd3_addr_cache* acache = & stream->acache; | 1574 | xd3_addr_cache* acache = & stream->acache; |
1561 | 1575 | ||
1562 | #define SMALLEST_INT(x) do { if (((x) & ~127U) == 0) { goto good; } } while (0) | 1576 | #define SMALLEST_INT(x) do { if (((x) & ~127U) == 0) { goto good; } } while (0) |
@@ -2869,7 +2883,7 @@ xd3_iopt_last_matched (xd3_stream *stream) | |||
2869 | ***********************************************************/ | 2883 | ***********************************************************/ |
2870 | 2884 | ||
2871 | static int | 2885 | static int |
2872 | xd3_emit_single (xd3_stream *stream, xd3_rinst *single, usize_t code) | 2886 | xd3_emit_single (xd3_stream *stream, xd3_rinst *single, uint8_t code) |
2873 | { | 2887 | { |
2874 | int has_size = stream->code_table[code].size1 == 0; | 2888 | int has_size = stream->code_table[code].size1 == 0; |
2875 | int ret; | 2889 | int ret; |
@@ -2898,7 +2912,7 @@ xd3_emit_single (xd3_stream *stream, xd3_rinst *single, usize_t code) | |||
2898 | 2912 | ||
2899 | static int | 2913 | static int |
2900 | xd3_emit_double (xd3_stream *stream, xd3_rinst *first, | 2914 | xd3_emit_double (xd3_stream *stream, xd3_rinst *first, |
2901 | xd3_rinst *second, usize_t code) | 2915 | xd3_rinst *second, uint8_t code) |
2902 | { | 2916 | { |
2903 | int ret; | 2917 | int ret; |
2904 | 2918 | ||
@@ -2968,8 +2982,8 @@ xd3_emit_hdr (xd3_stream *stream) | |||
2968 | int use_secondary = stream->sec_type != NULL; | 2982 | int use_secondary = stream->sec_type != NULL; |
2969 | int use_adler32 = stream->flags & (XD3_ADLER32 | XD3_ADLER32_RECODE); | 2983 | int use_adler32 = stream->flags & (XD3_ADLER32 | XD3_ADLER32_RECODE); |
2970 | int vcd_source = xd3_encoder_used_source (stream); | 2984 | int vcd_source = xd3_encoder_used_source (stream); |
2971 | usize_t win_ind = 0; | 2985 | uint8_t win_ind = 0; |
2972 | usize_t del_ind = 0; | 2986 | uint8_t del_ind = 0; |
2973 | usize_t enc_len; | 2987 | usize_t enc_len; |
2974 | usize_t tgt_len; | 2988 | usize_t tgt_len; |
2975 | usize_t data_len; | 2989 | usize_t data_len; |
@@ -2978,7 +2992,7 @@ xd3_emit_hdr (xd3_stream *stream) | |||
2978 | 2992 | ||
2979 | if (stream->current_window == 0) | 2993 | if (stream->current_window == 0) |
2980 | { | 2994 | { |
2981 | usize_t hdr_ind = 0; | 2995 | uint8_t hdr_ind = 0; |
2982 | int use_appheader = stream->enc_appheader != NULL; | 2996 | int use_appheader = stream->enc_appheader != NULL; |
2983 | 2997 | ||
2984 | if (use_secondary) { hdr_ind |= VCD_SECONDARY; } | 2998 | if (use_secondary) { hdr_ind |= VCD_SECONDARY; } |
@@ -3229,6 +3243,7 @@ xd3_encode_init (xd3_stream *stream, int full_init) | |||
3229 | * identical or short inputs require no table allocation. */ | 3243 | * identical or short inputs require no table allocation. */ |
3230 | if (large_comp) | 3244 | if (large_comp) |
3231 | { | 3245 | { |
3246 | /* TODO(jmacd) Need to check for overflow here. */ | ||
3232 | usize_t hash_values = stream->src->max_winsize / | 3247 | usize_t hash_values = stream->src->max_winsize / |
3233 | stream->smatcher.large_step; | 3248 | stream->smatcher.large_step; |
3234 | 3249 | ||
@@ -3927,6 +3942,7 @@ xd3_srcwin_setup (xd3_stream *stream) | |||
3927 | * issued, but we have to decide the source window base and length | 3942 | * issued, but we have to decide the source window base and length |
3928 | * now. */ | 3943 | * now. */ |
3929 | src->srcbase = stream->match_minaddr; | 3944 | src->srcbase = stream->match_minaddr; |
3945 | /* TODO(jmacd) Need to check for overflow here. */ | ||
3930 | src->srclen = max ((usize_t) length, | 3946 | src->srclen = max ((usize_t) length, |
3931 | stream->avail_in + (stream->avail_in >> 2)); | 3947 | stream->avail_in + (stream->avail_in >> 2)); |
3932 | 3948 | ||
@@ -4105,19 +4121,19 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) | |||
4105 | return 1; | 4121 | return 1; |
4106 | } | 4122 | } |
4107 | 4123 | ||
4108 | static inline int | 4124 | static inline usize_t |
4109 | xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, int n) | 4125 | xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, usize_t n) |
4110 | { | 4126 | { |
4111 | int i = 0; | 4127 | usize_t i = 0; |
4112 | #if UNALIGNED_OK | 4128 | #if UNALIGNED_OK |
4113 | int nint = n / sizeof(int); | 4129 | usize_t nint = n / sizeof(int); |
4114 | 4130 | ||
4115 | if (nint >> 3) | 4131 | if (nint >> 3) |
4116 | { | 4132 | { |
4117 | int j = 0; | 4133 | usize_t j = 0; |
4118 | const int *s1 = (const int*)s1c; | 4134 | const int *s1 = (const int*)s1c; |
4119 | const int *s2 = (const int*)s2c; | 4135 | const int *s2 = (const int*)s2c; |
4120 | int nint_8 = nint - 8; | 4136 | usize_t nint_8 = nint - 8; |
4121 | 4137 | ||
4122 | while (i <= nint_8 && | 4138 | while (i <= nint_8 && |
4123 | s1[i++] == s2[j++] && | 4139 | s1[i++] == s2[j++] && |
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index 69204c5..a643526 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h | |||
@@ -738,8 +738,8 @@ struct _xd3_source | |||
738 | usize_t srclen; /* length of this source window */ | 738 | usize_t srclen; /* length of this source window */ |
739 | xoff_t srcbase; /* offset of this source window | 739 | xoff_t srcbase; /* offset of this source window |
740 | in the source itself */ | 740 | in the source itself */ |
741 | int shiftby; /* for power-of-two blocksizes */ | 741 | usize_t shiftby; /* for power-of-two blocksizes */ |
742 | int maskby; /* for power-of-two blocksizes */ | 742 | usize_t maskby; /* for power-of-two blocksizes */ |
743 | xoff_t cpyoff_blocks; /* offset of dec_cpyoff in blocks */ | 743 | xoff_t cpyoff_blocks; /* offset of dec_cpyoff in blocks */ |
744 | usize_t cpyoff_blkoff; /* offset of copy window in | 744 | usize_t cpyoff_blkoff; /* offset of copy window in |
745 | blocks, remainder */ | 745 | blocks, remainder */ |
@@ -800,7 +800,7 @@ struct _xd3_stream | |||
800 | xd3_free_func *free; /* free function */ | 800 | xd3_free_func *free; /* free function */ |
801 | void* opaque; /* private data object passed to | 801 | void* opaque; /* private data object passed to |
802 | alloc, free, and getblk */ | 802 | alloc, free, and getblk */ |
803 | int flags; /* various options */ | 803 | uint32_t flags; /* various options */ |
804 | 804 | ||
805 | /* secondary compressor configuration */ | 805 | /* secondary compressor configuration */ |
806 | xd3_sec_cfg sec_data; /* Secondary compressor config: data */ | 806 | xd3_sec_cfg sec_data; /* Secondary compressor config: data */ |
@@ -1292,7 +1292,7 @@ usize_t xd3_encoder_srclen (xd3_stream *stream) { | |||
1292 | 1292 | ||
1293 | /* Checks for legal flag changes. */ | 1293 | /* Checks for legal flag changes. */ |
1294 | static inline | 1294 | static inline |
1295 | void xd3_set_flags (xd3_stream *stream, int flags) | 1295 | void xd3_set_flags (xd3_stream *stream, uint32_t flags) |
1296 | { | 1296 | { |
1297 | /* The bitwise difference should contain only XD3_FLUSH or | 1297 | /* The bitwise difference should contain only XD3_FLUSH or |
1298 | XD3_SKIP_WINDOW */ | 1298 | XD3_SKIP_WINDOW */ |