mspatcha: Use the standard max() and min() macros.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
stable
Zebediah Figura 2019-08-01 18:54:00 -05:00 committed by Alexandre Julliard
parent 3f848c3a16
commit 31cbdfa49e
2 changed files with 16 additions and 21 deletions

View File

@ -54,8 +54,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
#define E8_TRANSFORM_LIMIT_BITS 30
#define E8_TRANSFORM_DEAD_ZONE 10
#define my_min(a, b) ((a) < (b) ? (a) : (b))
struct LZXD_dec {
/* use byte pointers instead of uint16 for simplicity on uncompressed
* chunks, and the stream is not 16-bit aligned anyway */
@ -120,7 +118,7 @@ static int init_chunk(struct LZXD_dec *dec, size_t index, size_t buf_limit)
dec->bit_pos = 0;
dec->tail_bits = 0;
dec->uncomp_chunk_end = my_min(buf_limit, index + MAX_CHUNK_UNCOMPRESSED_SIZE);
dec->uncomp_chunk_end = min(buf_limit, index + MAX_CHUNK_UNCOMPRESSED_SIZE);
return 0;
}
@ -407,8 +405,8 @@ static int copy_uncompressed(struct LZXD_dec *dec, BYTE *base, size_t *index_ptr
while (dec->src < dec->stream_end)
{
/* now treat the input as an unaligned byte stream */
size_t to_copy = my_min(end - index, dec->uncomp_chunk_end - index);
to_copy = my_min(to_copy, (size_t)(dec->stream_end - dec->src));
size_t to_copy = min(end - index, dec->uncomp_chunk_end - index);
to_copy = min(to_copy, (size_t)(dec->stream_end - dec->src));
memcpy(base + index, dec->src, to_copy);
index += to_copy;
@ -522,7 +520,7 @@ static int decode_lzxd_block(struct LZXD_dec *dec, BYTE *base, size_t predef_siz
ret_if_failed(make_huffman_codes(codes, dec->len_lengths, LEN_CODE_COUNT));
make_decode_table(dec->len_table, codes, dec->len_lengths, MAX_CODE_LEN, LEN_CODE_COUNT);
block_limit = my_min(buf_limit, index + block_size);
block_limit = min(buf_limit, index + block_size);
while (index < block_limit)
{
@ -606,7 +604,7 @@ static int decode_lzxd_block(struct LZXD_dec *dec, BYTE *base, size_t predef_siz
--length;
}
end = my_min(index + length, block_limit);
end = min(index + length, block_limit);
while (index < end)
{
base[index] = base[index - dist];
@ -624,12 +622,12 @@ static int decode_lzxd_block(struct LZXD_dec *dec, BYTE *base, size_t predef_siz
static void reverse_e8_transform(BYTE *decode_buf, ptrdiff_t len, ptrdiff_t e8_file_size)
{
ptrdiff_t limit = my_min((ptrdiff_t)1 << E8_TRANSFORM_LIMIT_BITS, len);
ptrdiff_t limit = min((ptrdiff_t)1 << E8_TRANSFORM_LIMIT_BITS, len);
ptrdiff_t i;
for (i = 0; i < limit; )
{
ptrdiff_t end = my_min(i + MAX_CHUNK_UNCOMPRESSED_SIZE - E8_TRANSFORM_DEAD_ZONE,
ptrdiff_t end = min(i + MAX_CHUNK_UNCOMPRESSED_SIZE - E8_TRANSFORM_DEAD_ZONE,
limit - E8_TRANSFORM_DEAD_ZONE);
ptrdiff_t next = i + MAX_CHUNK_UNCOMPRESSED_SIZE;

View File

@ -50,9 +50,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
#define PA19_FILE_MAGIC 0x39314150
#define PATCH_OPTION_EXTRA_FLAGS 0x80000000
#define my_max(a, b) ((a) > (b) ? (a) : (b))
#define my_min(a, b) ((a) < (b) ? (a) : (b))
static UINT32 compute_zero_crc32(UINT32 crc, INT_PTR len)
{
static const BYTE zero_buffer[1024];
@ -173,7 +170,7 @@ static UINT64 read_uvli(struct patch_file_header *ph)
const BYTE *vli = ph->src;
UINT64 n;
ptrdiff_t i;
ptrdiff_t limit = my_min(ph->end - vli, 9);
ptrdiff_t limit = min(ph->end - vli, 9);
if (ph->src >= ph->end)
{
@ -204,7 +201,7 @@ static INT64 read_svli(struct patch_file_header *ph)
const BYTE *vli = ph->src;
INT64 n;
ptrdiff_t i;
ptrdiff_t limit = my_min(ph->end - vli, 9);
ptrdiff_t limit = min(ph->end - vli, 9);
if (ph->src >= ph->end)
{
@ -423,7 +420,7 @@ static int read_header(struct patch_file_header *ph, const BYTE *buf, size_t siz
}
/* skip the crc adjustment field */
ph->src = my_min(ph->src + 4, ph->end);
ph->src = min(ph->src + 4, ph->end);
{
UINT32 crc = RtlComputeCrc32(0, buf, ph->src - buf) ^ 0xFFFFFFFF;
@ -464,8 +461,8 @@ static ULONG next_ignored_range(const struct input_file_info *fi, size_t index,
if (fi->next_i < fi->ignore_range_count && fi->stream_size != 0)
{
start = fi->ignore_table[fi->next_i].OffsetInOldFile;
*end = my_max(start + fi->ignore_table[fi->next_i].LengthInBytes, index);
start = my_max(start, index);
*end = max(start + fi->ignore_table[fi->next_i].LengthInBytes, index);
start = max(start, index);
}
return start;
}
@ -479,8 +476,8 @@ static ULONG next_retained_range_old(const struct input_file_info *fi, size_t in
if (fi->next_r < fi->retain_range_count)
{
start = fi->retain_table[fi->next_r].OffsetInOldFile;
*end = my_max(start + fi->retain_table[fi->next_r].LengthInBytes, index);
start = my_max(start, index);
*end = max(start + fi->retain_table[fi->next_r].LengthInBytes, index);
start = max(start, index);
}
return start;
}
@ -494,8 +491,8 @@ static ULONG next_retained_range_new(const struct input_file_info *fi, size_t in
if (fi->next_r < fi->retain_range_count)
{
start = fi->retain_table[fi->next_r].OffsetInNewFile;
*end = my_max(start + fi->retain_table[fi->next_r].LengthInBytes, index);
start = my_max(start, index);
*end = max(start + fi->retain_table[fi->next_r].LengthInBytes, index);
start = max(start, index);
}
return start;
}