From 3ddb1d31662d069292095cc24bee639cce7bdf3c Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 15 Apr 2020 16:33:22 -0400 Subject: [PATCH] EGCPool: early realloc failure is not a hard fail We do proactive reallocations of the EGCPool once we get to 90% capacity, to avoid expensive exhaustive searches. When we're over half the maximum size, though, this will fail. We shouldn't treat that as a hard failure, but instead proceed on to the search. This lets us hit the full 32MB EGCPool size #486. --- src/lib/egcpool.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/egcpool.h b/src/lib/egcpool.h index 8581c56bb..32b6e3c1d 100644 --- a/src/lib/egcpool.h +++ b/src/lib/egcpool.h @@ -43,8 +43,7 @@ egcpool_grow(egcpool* pool, size_t len){ while(len > newsize - pool->poolsize){ // ensure we make enough space newsize *= 2; } - // offsets only have 25 bits available... - if(newsize >= 1u << 25u){ + if(newsize > 1u << 25u){ return -1; } // 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){ duplicated = strdup(egc); } - if(egcpool_grow(pool, len)){ + if(egcpool_grow(pool, len) && searched){ free(duplicated); 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 // back to where we started, force a growth and try again. int curpos = pool->poolwrite; +//fprintf(stderr, "Stashing [%s] %d starting at %d\n", egc, len, curpos); do{ if(curpos == pool->poolsize){ curpos = 0; @@ -167,6 +167,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){ pool->poolwrite = curpos + len; pool->poolused += len; free(duplicated); +//fprintf(stderr, "Stashing AT %d\n", curpos); return curpos; } if(pool->poolwrite > curpos && pool->poolwrite - (len - need) < curpos){