Skip to content

Commit

Permalink
egcpool.h: update comment (we can store 4 bytes in an nccell), check …
Browse files Browse the repository at this point in the history
…for overflow
  • Loading branch information
dankamongmen committed Dec 2, 2024
1 parent 20bed5e commit 3a3c75e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lib/egcpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
extern "C" {
#endif

// cells only provide storage for a single 7-bit character. if there's anything
// more than that, it's spilled into the egcpool, and the cell is given an
// offset. when a cell is released, the memory it owned is zeroed out, and
// recognizable as use for another cell.
// an nccell only provides storage for up to 4 bytes of an EGC. if there's
// anything more than that, it's spilled into the egcpool, and the nccell
// records the offset. when an nccell is released, the egcpool memory it
// owned is zeroed out, and made usable by another nccell.

typedef struct egcpool {
char* pool; // ringbuffer of attached extension storage
Expand All @@ -43,10 +43,16 @@ egcpool_init(egcpool* p){
static inline int
egcpool_grow(egcpool* pool, size_t len){
size_t newsize = pool->poolsize * 2;
if(newsize < pool->poolsize){
return -1; // pernicious overflow (see also POOL_MAXIMUM_BYTES check below)
}
if(newsize < POOL_MINIMUM_ALLOC){
newsize = POOL_MINIMUM_ALLOC;
}
while(len > newsize - pool->poolsize){ // ensure we make enough space
if(newsize * 2 < newsize){
return -1;
}
newsize *= 2;
}
if(newsize > POOL_MAXIMUM_BYTES){
Expand Down

0 comments on commit 3a3c75e

Please sign in to comment.