Well I didn't expect bugs here. How long has that math been wrong?

This commit is contained in:
Alcaro 2015-11-04 20:18:09 +01:00
parent 53b96c19af
commit 65a97a6a87

View File

@ -95,7 +95,7 @@ size_t state_manager_raw_maxsize(size_t uncomp)
/* bytes covered by a compressed block */
const int maxcblkcover = UINT16_MAX * sizeof(uint16_t);
/* uncompressed size, rounded to 16 bits */
size_t uncomp16 = (uncomp + sizeof(uint16_t) - 1) & ~sizeof(uint16_t);
size_t uncomp16 = (uncomp + sizeof(uint16_t) - 1) & -sizeof(uint16_t);
/* number of blocks */
size_t maxcblks = (uncomp + maxcblkcover - 1) / maxcblkcover;
return uncomp16 + maxcblks * sizeof(uint16_t) * 2 /* two u16 overhead per block */ + sizeof(uint16_t) *
@ -104,7 +104,7 @@ size_t state_manager_raw_maxsize(size_t uncomp)
void *state_manager_raw_alloc(size_t len, uint16_t uniq)
{
size_t len16 = (len + sizeof(uint16_t) - 1) & ~sizeof(uint16_t);
size_t len16 = (len + sizeof(uint16_t) - 1) & -sizeof(uint16_t);
uint16_t *ret = (uint16_t*)calloc(len16 + sizeof(uint16_t) * 4 + 16, 1);