# HG changeset patch # User Matti Hamalainen # Date 1583785769 -7200 # Node ID fd31b5d1ed5e4b0bc860d18e08d76c53138003ff # Parent d18fd4866650c9980a678b3447cfa8b9cd1b388b Add few comments. diff -r d18fd4866650 -r fd31b5d1ed5e src/dmres.c --- a/src/dmres.c Tue Mar 03 14:31:14 2020 +0200 +++ b/src/dmres.c Mon Mar 09 22:29:29 2020 +0200 @@ -569,15 +569,18 @@ { size_t grow; + // Check against max size if (ctx->maxSize > 0 && newSize > ctx->maxSize) { ctx->error = DMERR_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; @@ -588,6 +591,7 @@ return FALSE; } + // Grow the buffer ctx->memAlloc += grow; if ((ctx->memData = dmRealloc(ctx->memData, ctx->memAlloc)) == NULL) { @@ -595,6 +599,7 @@ return FALSE; } +out: ctx->memSize = newSize; return TRUE;