summaryrefslogtreecommitdiff
path: root/xdelta3-djw.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3-djw.h')
-rw-r--r--xdelta3-djw.h60
1 files changed, 28 insertions, 32 deletions
diff --git a/xdelta3-djw.h b/xdelta3-djw.h
index a4c7e51..d6e2881 100644
--- a/xdelta3-djw.h
+++ b/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[%"W"u] = %u\n", i, ents[heap[i]].freq));
+ IF_DEBUG2 (DP(RINT "heap[%d] = %u\n", i, ents[heap[i]].freq));
}
}
#endif
@@ -343,7 +343,7 @@ static inline void
djw_update_1_2 (int *mtf_run, usize_t *mtf_i,
uint8_t *mtfsym, djw_weight *freq)
{
- uint8_t code;
+ int code;
do
{
@@ -395,16 +395,16 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
usize_t heap_last; /* Index of the last _valid_ heap entry. */
usize_t ents_size; /* Number of entries, including 0th fake entry */
usize_t overflow; /* Number of code lengths that overflow */
- usize_t total_bits;
+ uint32_t total_bits;
usize_t i;
- IF_DEBUG (usize_t first_bits = 0);
+ IF_DEBUG (uint32_t first_bits = 0);
/* Insert real symbol frequences. */
for (i = 0; i < asize; i += 1)
{
ents[i+1].freq = freq[i];
- IF_DEBUG2 (DP(RINT "ents[%"W"i] = freq[%"W"u] = %d\n",
+ IF_DEBUG2 (DP(RINT "ents[%d] = freq[%d] = %d\n",
i+1, i, freq[i]));
}
@@ -444,7 +444,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
if (heap_last == 1)
{
/* Pick either the first or last symbol. */
- usize_t s = freq[0] ? asize-1 : 0;
+ int s = freq[0] ? asize-1 : 0;
ents[s+1].freq = 1;
goto again;
}
@@ -456,7 +456,7 @@ djw_build_prefix (const djw_weight *freq, uint8_t *clen, usize_t asize, usize_t
djw_heapen *h2 = heap_extract (heap, ents, --heap_last);
ents[ents_size].freq = h1->freq + h2->freq;
- ents[ents_size].depth = 1 + xd3_max (h1->depth, h2->depth);
+ ents[ents_size].depth = 1 + max (h1->depth, h2->depth);
ents[ents_size].parent = 0;
h1->parent = h2->parent = ents_size;
@@ -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[%"W"u] = %"W"u\n", i-1, b));
+ IF_DEBUG2 (DP(RINT "clen[%d] = %d\n", i-1, b));
clen[i-1] = b;
}
@@ -493,8 +493,8 @@ 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 %"W"u bits\n",
- total_bits - first_bits);
+ DP(RINT "code length overflow changed %u bits\n",
+ (usize_t)(total_bits - first_bits));
});
return total_bits;
}
@@ -525,7 +525,7 @@ djw_build_codes (usize_t *codes, const uint8_t *clen, usize_t asize, usize_t abs
min_clen = clen[i];
}
- max_clen = xd3_max (max_clen, (usize_t) clen[i]);
+ max_clen = max (max_clen, (usize_t) clen[i]);
}
XD3_ASSERT (max_clen <= abs_max);
@@ -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[%"W"u] = %"W"u\n", i, codes[i]);
+ DP(RINT "code[%d] = %u\n", i, codes[i]);
}
});
}
@@ -869,7 +869,7 @@ xd3_encode_huff (xd3_stream *stream,
usize_t groups, sector_size;
bit_state bstate = BIT_STATE_ENCODE_INIT;
xd3_output *in;
- usize_t output_bits;
+ int output_bits;
usize_t input_bits;
usize_t input_bytes;
usize_t initial_offset = output->next;
@@ -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 (%"W"u), dropping one\n",
+ IF_DEBUG2 (DP(RINT "too many groups (%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 %"W"u has symbols %"W"u..%"W"u (%"W"u non-zero) "
- "(%u/%"W"u = %.3f)\n",
+ IF_DEBUG2(DP(RINT "group %u has symbols %u..%u (%u non-zero) "
+ "(%u/%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 %"W"u bits in group %"W"u\n",
+ IF_DEBUG2 (DP(RINT "evolve_zero reduced %u bits in group %u\n",
save_total - output_bits, gp));
}
}
IF_DEBUG2(
- 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 "pass %u total bits: %u group uses: ", niter, output_bits);
+ for (gp = 0; gp < groups; gp += 1) { DP(RINT "%u ", gcount[gp]); }
DP(RINT "\n");
);
/* End iteration. */
IF_DEBUG2 (if (niter > 1 && best_bits < output_bits) {
- DP(RINT "iteration lost %"W"u bits\n", output_bits - best_bits); });
+ DP(RINT "iteration lost %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: %"W"u -> %0.3f\n",
+ IF_DEBUG2 (DP(RINT "djw compression: %u -> %0.3f\n",
input_bytes, output_bits / 8.0));
/* Encode: prefix */
@@ -1456,7 +1456,7 @@ djw_decode_symbol (xd3_stream *stream,
if (*input == input_end)
{
stream->msg = "secondary decoder end of input";
- return XD3_INVALID_INPUT;
+ return XD3_INTERNAL;
}
bstate->cur_byte = *(*input)++;
@@ -1471,7 +1471,7 @@ djw_decode_symbol (xd3_stream *stream,
if (offset <= max_sym)
{
- IF_DEBUG2 (DP(RINT "(j) %"W"u ", code));
+ IF_DEBUG2 (DP(RINT "(j) %u ", code));
*sym = inorder[offset];
return 0;
}
@@ -1479,7 +1479,7 @@ djw_decode_symbol (xd3_stream *stream,
corrupt:
stream->msg = "secondary decoder invalid code";
- return XD3_INVALID_INPUT;
+ return XD3_INTERNAL;
}
static int
@@ -1606,7 +1606,7 @@ djw_decode_1_2 (xd3_stream *stream,
if (rep != 0)
{
stream->msg = "secondary decoder invalid repeat code";
- return XD3_INVALID_INPUT;
+ return XD3_INTERNAL;
}
return 0;
@@ -1654,7 +1654,7 @@ xd3_decode_huff (xd3_stream *stream,
if (output_bytes == 0)
{
stream->msg = "secondary decoder invalid input";
- return XD3_INVALID_INPUT;
+ return XD3_INTERNAL;
}
/* Decode: number of groups */
@@ -1796,14 +1796,10 @@ xd3_decode_huff (xd3_stream *stream,
gp_maxlen = maxlen[gp];
}
- if (output_end < output)
- {
- stream->msg = "secondary decoder invalid input";
- return XD3_INVALID_INPUT;
- }
+ XD3_ASSERT (output_end - output > 0);
/* Decode next sector. */
- n = xd3_min (sector_size, (usize_t) (output_end - output));
+ n = min (sector_size, (usize_t) (output_end - output));
do
{