MCPcopy Create free account
hub / github.com/Kitware/CMake / poolGrow

Function poolGrow

Utilities/cmexpat/lib/xmlparse.c:8105–8206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8103}
8104
8105static XML_Bool FASTCALL
8106poolGrow(STRING_POOL *pool) {
8107 if (pool->freeBlocks) {
8108 if (pool->start == 0) {
8109 pool->blocks = pool->freeBlocks;
8110 pool->freeBlocks = pool->freeBlocks->next;
8111 pool->blocks->next = NULL;
8112 pool->start = pool->blocks->s;
8113 pool->end = pool->start + pool->blocks->size;
8114 pool->ptr = pool->start;
8115 return XML_TRUE;
8116 }
8117 if (pool->end - pool->start < pool->freeBlocks->size) {
8118 BLOCK *tem = pool->freeBlocks->next;
8119 pool->freeBlocks->next = pool->blocks;
8120 pool->blocks = pool->freeBlocks;
8121 pool->freeBlocks = tem;
8122 memcpy(pool->blocks->s, pool->start,
8123 (pool->end - pool->start) * sizeof(XML_Char));
8124 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
8125 pool->start = pool->blocks->s;
8126 pool->end = pool->start + pool->blocks->size;
8127 return XML_TRUE;
8128 }
8129 }
8130 if (pool->blocks && pool->start == pool->blocks->s) {
8131 BLOCK *temp;
8132 int blockSize = (int)((unsigned)(pool->end - pool->start) * 2U);
8133 size_t bytesToAllocate;
8134
8135 /* NOTE: Needs to be calculated prior to calling `realloc`
8136 to avoid dangling pointers: */
8137 const ptrdiff_t offsetInsideBlock = pool->ptr - pool->start;
8138
8139 if (blockSize < 0) {
8140 /* This condition traps a situation where either more than
8141 * INT_MAX/2 bytes have already been allocated. This isn't
8142 * readily testable, since it is unlikely that an average
8143 * machine will have that much memory, so we exclude it from the
8144 * coverage statistics.
8145 */
8146 return XML_FALSE; /* LCOV_EXCL_LINE */
8147 }
8148
8149 bytesToAllocate = poolBytesToAllocateFor(blockSize);
8150 if (bytesToAllocate == 0)
8151 return XML_FALSE;
8152
8153 temp = REALLOC(pool->parser, pool->blocks, bytesToAllocate);
8154 if (temp == NULL)
8155 return XML_FALSE;
8156 pool->blocks = temp;
8157 pool->blocks->size = blockSize;
8158 pool->ptr = pool->blocks->s + offsetInsideBlock;
8159 pool->start = pool->blocks->s;
8160 pool->end = pool->start + blockSize;
8161 } else {
8162 BLOCK *tem;

Callers 4

storeEntityValueFunction · 0.85
poolAppendFunction · 0.85
poolCopyStringNFunction · 0.85
poolStoreStringFunction · 0.85

Calls 1

poolBytesToAllocateForFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…