MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / dynbuf_ensure

Function dynbuf_ensure

internal/cbm/sqlite_writer.c:319–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

317}
318
319static bool dynbuf_ensure(DynBuf *b, int needed) {
320 if (b->len + needed <= b->cap) {
321 return true;
322 }
323 int newcap = b->cap < INITIAL_PAGE_CAP ? INITIAL_PAGE_CAP : b->cap;
324 while (newcap < b->len + needed) {
325 newcap *= GROWTH_FACTOR;
326 }
327 uint8_t *p = b->heap ? (uint8_t *)realloc(b->data, newcap) : (uint8_t *)malloc(newcap);
328 if (!p) {
329 (void)fprintf(stderr, "cbm_write_db: dynbuf realloc failed size=%d\n", newcap);
330 return false;
331 }
332 if (!b->heap && b->len > 0) {
333 memcpy(p, b->data, (size_t)b->len);
334 }
335 b->data = p;
336 b->cap = newcap;
337 b->heap = true;
338 return true;
339}
340
341static bool dynbuf_append(DynBuf *b, const void *data, int len) {
342 if (len <= 0) {

Callers 1

dynbuf_appendFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected