comparison src/dmres.c @ 2444:fd31b5d1ed5e

Add few comments.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2020 22:29:29 +0200
parents f7d54ac51880
children fa089a430121
comparison
equal deleted inserted replaced
2443:d18fd4866650 2444:fd31b5d1ed5e
567 567
568 static BOOL dm_mem_realloc(DMResource *ctx, const size_t newSize) 568 static BOOL dm_mem_realloc(DMResource *ctx, const size_t newSize)
569 { 569 {
570 size_t grow; 570 size_t grow;
571 571
572 // Check against max size
572 if (ctx->maxSize > 0 && newSize > ctx->maxSize) 573 if (ctx->maxSize > 0 && newSize > ctx->maxSize)
573 { 574 {
574 ctx->error = DMERR_BOUNDS; 575 ctx->error = DMERR_BOUNDS;
575 return FALSE; 576 return FALSE;
576 } 577 }
577 578
579 // New size is smaller than old
578 if (newSize < ctx->memAlloc) 580 if (newSize < ctx->memAlloc)
579 return TRUE; 581 goto out;
580 582
583 // Compute the allocation grow amount
581 grow = (ctx->minAlloc > 0) ? ctx->minAlloc : 8 * 1024; 584 grow = (ctx->minAlloc > 0) ? ctx->minAlloc : 8 * 1024;
582 if (newSize - ctx->memAlloc > grow) 585 if (newSize - ctx->memAlloc > grow)
583 grow += newSize - ctx->memAlloc; 586 grow += newSize - ctx->memAlloc;
584 587
585 if (ctx->maxSize > 0 && ctx->memAlloc + grow >= ctx->maxSize) 588 if (ctx->maxSize > 0 && ctx->memAlloc + grow >= ctx->maxSize)
586 { 589 {
587 ctx->error = DMERR_BOUNDS; 590 ctx->error = DMERR_BOUNDS;
588 return FALSE; 591 return FALSE;
589 } 592 }
590 593
594 // Grow the buffer
591 ctx->memAlloc += grow; 595 ctx->memAlloc += grow;
592 if ((ctx->memData = dmRealloc(ctx->memData, ctx->memAlloc)) == NULL) 596 if ((ctx->memData = dmRealloc(ctx->memData, ctx->memAlloc)) == NULL)
593 { 597 {
594 ctx->error = DMERR_MALLOC; 598 ctx->error = DMERR_MALLOC;
595 return FALSE; 599 return FALSE;
596 } 600 }
597 601
602 out:
598 ctx->memSize = newSize; 603 ctx->memSize = newSize;
599 604
600 return TRUE; 605 return TRUE;
601 } 606 }
602 607