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

Function jl_buffer_reserve

src/cli/config_json_like.c:947–970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

945}
946
947static int jl_buffer_reserve(jl_buffer_t *buffer, size_t additional) {
948 if (additional > SIZE_MAX - buffer->length - 1U) {
949 return -1;
950 }
951 size_t needed = buffer->length + additional + 1U;
952 if (needed <= buffer->capacity) {
953 return 0;
954 }
955 size_t capacity = buffer->capacity ? buffer->capacity : 128U;
956 while (capacity < needed) {
957 if (capacity > SIZE_MAX / 2U) {
958 capacity = needed;
959 break;
960 }
961 capacity *= 2U;
962 }
963 char *grown = realloc(buffer->data, capacity);
964 if (!grown) {
965 return -1;
966 }
967 buffer->data = grown;
968 buffer->capacity = capacity;
969 return 0;
970}
971
972static int jl_buffer_append(jl_buffer_t *buffer, const char *data, size_t length) {
973 if (jl_buffer_reserve(buffer, length) != 0) {

Callers 1

jl_buffer_appendFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected