(libchdr) Cleanups + attempts to rebase against upstream

This commit is contained in:
twinaphex 2020-07-01 19:12:20 +02:00
parent d50c49c4e8
commit 88804a05de
3 changed files with 13 additions and 11 deletions

View File

@ -335,7 +335,8 @@ enum huffman_error huffman_compute_tree_from_histo(struct huffman_decoder* decod
/* binary search to achieve the optimum encoding */
upperweight = sdatacount * 2;
while (1)
for (;;)
{
/* build a tree using the current weight */
uint32_t curweight = (upperweight + lowerweight) / 2;
@ -548,16 +549,13 @@ void huffman_build_lookup_table(struct huffman_decoder* decoder)
struct node_t* node = &decoder->huffnode[curcode];
if (node->numbits > 0)
{
int shift;
lookup_value *dest;
lookup_value *destend;
/* set up the entry */
lookup_value value = MAKE_LOOKUP(curcode, node->numbits);
/* fill all matching entries */
shift = decoder->maxbits - node->numbits;
dest = &decoder->lookup[node->bits << shift];
destend = &decoder->lookup[((node->bits + 1) << shift) - 1];
int shift = decoder->maxbits - node->numbits;
lookup_value *dest = &decoder->lookup[node->bits << shift];
lookup_value *destend = &decoder->lookup[((node->bits + 1) << shift) - 1];
while (dest <= destend)
*dest++ = value;
}

View File

@ -103,7 +103,7 @@ static void *lzma_fast_alloc(void *p, size_t size)
/* set the low bit of the size so we don't match next time */
*addr = (uint32_t)(size | 1);
return addr + 1;
return addr + (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
}
/*-------------------------------------------------

View File

@ -174,6 +174,10 @@ chd_error zlib_codec_init(void *codec, uint32_t hunkbytes)
else
err = CHDERR_NONE;
/* handle an error */
if (err != CHDERR_NONE)
free(data);
return err;
}
@ -225,7 +229,7 @@ chd_error zlib_codec_decompress(void *codec, const uint8_t *src, uint32_t comple
/* do it */
zerr = inflate(&data->inflater, Z_FINISH);
(void)zerr;
(void)zerr;
if (data->inflater.total_out != destlen)
return CHDERR_DECOMPRESSION_ERROR;
@ -273,7 +277,7 @@ voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size)
/* set the low bit of the size so we don't match next time */
*ptr = size | 1;
return ptr + 1;
return ptr + (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
}
/*-------------------------------------------------
@ -284,7 +288,7 @@ voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size)
void zlib_fast_free(voidpf opaque, voidpf address)
{
zlib_allocator *alloc = (zlib_allocator *)opaque;
UINT32 *ptr = (UINT32 *)address - 1;
UINT32 *ptr = (UINT32 *)address - (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
int i;
/* find the hunk */