![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
awsdert
After adding some print statements to track the results of tables I found it's not the reading of the encoding thats the issue, its the point that I move each symbol to an index that matches it's uid (for speed during the deflation process):
Code:
typedef struct _ZLIB_SYMBOL
{
uint uid;
uint src;
uint val;
uint sym;
uint lit;
uint len;
uint get;
uint cpy;
uint use;
uint nxt[2];
} ZLIB_SYMBOL;
...
int CompareSymbols( void const *A, void const *B )
{
ZLIB_SYMBOL const *a = A, *b = B;
if ( a->use != b->use )
return b->use - a->use;
if ( a->len != b->len )
return a->len - b->len;
return a->uid - b->uid;
}
...
int SortZlibSymbolsByUID( ZLIB *zlib, int id )
{
uint j = 0;
ZLIB_SYMBOLS *Symbols = &(zlib->Symbols[id]);
BUFFER *Entries = AccessBuffer( zlib->Buffers, Symbols->entries );
ZLIB_SYMBOL *symbols = Entries->addr, *dst, *src;
FILE *verbose = zlib->Buffers->Alloc->verbose;
if ( verbose && !quiet_zlib )
{
ECHO
(
verbose,
fprintf( verbose, "Prior to qsort() " );
EchoZlibSymbolsListDetails( verbose, zlib, id )
);
}
qsort( symbols, Entries->used, sizeof(ZLIB_SYMBOL), CompareSymbols );
if ( verbose && !quiet_zlib )
{
ECHO
(
verbose,
fprintf( verbose, "Prior to manual " );
EchoZlibSymbolsListDetails( verbose, zlib, id )
);
}
symbols = GrowZlibSymbolsBuffer( zlib, id, Symbols->highest + 1 );
if ( !symbols )
return ENOMEM;
for ( j = Entries->used - 1; j; --j )
{
src = symbols + j;
dst = symbols + src->uid;
if ( src->uid > j )
{
*dst = *src;
/* This is where I'm loosing data when I shouldn't be (in theory anyways) */
memset( src, 0, sizeof(ZLIB_SYMBOL) );
}
}
Entries->used = Symbols->highest + 1;
return 0;
}
I've added a comment to the point I can see is causing the error down the line, although in theory shouldn't be, any ideas on how to fix it? Or even better any ideas on how to fob off the duty to CompareSymbols()?
Your problem is in here, from "buffer.c".
Code:
#include "memory.h"
void * default_allocator( void *ud, void *ptr, size_t had, size_t get )
{
uchar *tmp;
(void)ud;
if ( !get )
{
if ( ptr )
free( ptr );
return NULL;
}
tmp = ptr ? malloc( get ) : realloc( ptr, get );
if ( !tmp )
return NULL;
if ( get > had )
memset( tmp + had, 0, get - had );
return tmp;
}
...