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

Function adr_render_section

src/store/store.c:11090–11111  ·  view source on GitHub ↗

Append a section to the render buffer. * * snprintf returns the length it WOULD have written, so a section larger than * the space left would otherwise push pos past buf_sz; the next call would then * compute a wrapped (huge) remaining size from (buf_sz - pos) and write out of * bounds. Clamp pos into [0, buf_sz-1] after every write so each snprintf gets * a positive size and the returned cu

Source from the content-addressed store, hash-verified

11088 * bounds. Clamp pos into [0, buf_sz-1] after every write so each snprintf gets
11089 * a positive size and the returned cursor never escapes the buffer. */
11090static int adr_render_section(char *buf, int buf_sz, int pos, const char *key, const char *value) {
11091 if (buf_sz <= 0) {
11092 return 0;
11093 }
11094 if (pos < 0) {
11095 pos = 0;
11096 }
11097 if (pos >= buf_sz) {
11098 return buf_sz - SKIP_ONE;
11099 }
11100 if (pos > 0) {
11101 pos += snprintf(buf + pos, (size_t)(buf_sz - pos), "\n\n");
11102 if (pos >= buf_sz) {
11103 return buf_sz - SKIP_ONE;
11104 }
11105 }
11106 pos += snprintf(buf + pos, (size_t)(buf_sz - pos), "## %s\n%s", key, value);
11107 if (pos >= buf_sz) {
11108 pos = buf_sz - SKIP_ONE;
11109 }
11110 return pos;
11111}
11112
11113char *cbm_adr_render(const cbm_adr_sections_t *sections) {
11114 if (!sections || sections->count == 0) {

Callers 1

cbm_adr_renderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected