@ -43,8 +43,7 @@ egcpool_grow(egcpool* pool, size_t len){
while ( len > newsize - pool - > poolsize ) { // ensure we make enough space
while ( len > newsize - pool - > poolsize ) { // ensure we make enough space
newsize * = 2 ;
newsize * = 2 ;
}
}
// offsets only have 25 bits available...
if ( newsize > 1u < < 25u ) {
if ( newsize > = 1u < < 25u ) {
return - 1 ;
return - 1 ;
}
}
// nasty cast here because c++ source might include this header :/
// nasty cast here because c++ source might include this header :/
@ -129,7 +128,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){
if ( ! duplicated ) {
if ( ! duplicated ) {
duplicated = strdup ( egc ) ;
duplicated = strdup ( egc ) ;
}
}
if ( egcpool_grow ( pool , len ) ) {
if ( egcpool_grow ( pool , len ) & & searched ) {
free ( duplicated ) ;
free ( duplicated ) ;
return - 1 ;
return - 1 ;
}
}
@ -140,6 +139,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){
// memory. if we find it, write it out, and update used count. if we come
// memory. if we find it, write it out, and update used count. if we come
// back to where we started, force a growth and try again.
// back to where we started, force a growth and try again.
int curpos = pool - > poolwrite ;
int curpos = pool - > poolwrite ;
//fprintf(stderr, "Stashing [%s] %d starting at %d\n", egc, len, curpos);
do {
do {
if ( curpos = = pool - > poolsize ) {
if ( curpos = = pool - > poolsize ) {
curpos = 0 ;
curpos = 0 ;
@ -167,6 +167,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){
pool - > poolwrite = curpos + len ;
pool - > poolwrite = curpos + len ;
pool - > poolused + = len ;
pool - > poolused + = len ;
free ( duplicated ) ;
free ( duplicated ) ;
//fprintf(stderr, "Stashing AT %d\n", curpos);
return curpos ;
return curpos ;
}
}
if ( pool - > poolwrite > curpos & & pool - > poolwrite - ( len - need ) < curpos ) {
if ( pool - > poolwrite > curpos & & pool - > poolwrite - ( len - need ) < curpos ) {