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

Function text_buffer_reserve

src/cli/config_text_edit.c:112–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static int text_buffer_reserve(text_buffer_t *buffer, size_t additional) {
113 if (!buffer || additional > SIZE_MAX - buffer->len - 1U) {
114 return TEXT_ERROR;
115 }
116 size_t required = buffer->len + additional + 1U;
117 if (required > (size_t)TEXT_MAX_BYTES + 1U) {
118 return TEXT_ERROR;
119 }
120 if (required <= buffer->capacity) {
121 return TEXT_OK;
122 }
123 size_t capacity = buffer->capacity ? buffer->capacity : 256U;
124 while (capacity < required) {
125 if (capacity > SIZE_MAX / 2U) {
126 capacity = required;
127 break;
128 }
129 capacity *= 2U;
130 }
131 char *grown = (char *)realloc(buffer->data, capacity);
132 if (!grown) {
133 return TEXT_ERROR;
134 }
135 buffer->data = grown;
136 buffer->capacity = capacity;
137 return TEXT_OK;
138}
139
140static int text_buffer_append(text_buffer_t *buffer, const char *data, size_t len) {
141 if ((!data && len != 0U) || text_buffer_reserve(buffer, len) != TEXT_OK) {

Callers 1

text_buffer_appendFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected