Mercurial > hg > th-libs
changeset 692:ea6bcbfb9d18
Comments and cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 09 Mar 2020 17:59:06 +0200 |
parents | 49c818acbbbe |
children | a622d21833e1 |
files | th_ioctx_mem.c |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/th_ioctx_mem.c Mon Mar 09 16:22:01 2020 +0200 +++ b/th_ioctx_mem.c Mon Mar 09 17:59:06 2020 +0200 @@ -12,15 +12,18 @@ { size_t grow; + // Check against max size if (ctx->maxSize > 0 && newSize > ctx->maxSize) { ctx->status = THERR_BOUNDS; return FALSE; } + // New size is smaller than old if (newSize < ctx->memAlloc) - return TRUE; + goto out; + // Compute the allocation grow amount grow = (ctx->minAlloc > 0) ? ctx->minAlloc : 8 * 1024; if (newSize - ctx->memAlloc > grow) grow += newSize - ctx->memAlloc; @@ -31,6 +34,7 @@ return FALSE; } + // Grow the buffer ctx->memAlloc += grow; if ((ctx->memData = th_realloc(ctx->memData, ctx->memAlloc)) == NULL) { @@ -38,6 +42,7 @@ return FALSE; } +out: ctx->memSize = newSize; return TRUE;