Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

doc-links(cs): a doc-line map that cannot grow fails the layer (R5)

Martin Vogelb3721128c155
diff --git a/internal/cbm/doclink.c b/internal/cbm/doclink.c
index 81d5a620f..d7d9b8b41 100644
--- a/internal/cbm/doclink.c
+++ b/internal/cbm/doclink.c
@@ -195,6 +195,15 @@ static CBMArena *doclink_scratch(CBMExtractCtx *ctx) {
return ctx->scratch ? ctx->scratch : ctx->arena;
}
+/* The map could not hold a doc: its references then take their definition's
+ * line, and a doc shared by several declarators is taken once per declarator.
+ * The layer must not say ok over that (CBMDocLinkArray.failed). */
+static void doc_line_lost(CBMExtractCtx *ctx) {
+ if (ctx->result) {
+ ctx->result->doc_links.failed = true;
+ }
+}
+
void cbm_doclink_note_doc_line(CBMExtractCtx *ctx, const char *doc, uint32_t line) {
if (!ctx || !doc || !cbm_doclink_lang_supported(ctx->language)) {
return;
@@ -204,6 +213,7 @@ void cbm_doclink_note_doc_line(CBMExtractCtx *ctx, const char *doc, uint32_t lin
if (!m) {
m = (doc_line_map_t *)cbm_arena_alloc(a, sizeof(*m));
if (!m) {
+ doc_line_lost(ctx);
return;
}
memset(m, 0, sizeof(*m));
@@ -211,9 +221,18 @@ void cbm_doclink_note_doc_line(CBMExtractCtx *ctx, const char *doc, uint32_t lin
}
if (m->count >= m->cap) {
int ncap = m->cap ? m->cap * PAIR_LEN : DOC_LINE_MAP_INIT;
- doc_line_ent_t *grown = (doc_line_ent_t *)cbm_arena_alloc(a, (size_t)ncap * sizeof(*grown));
+ doc_line_ent_t *grown;
+#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
+ if (cbm_doclink_test_fail_alloc(CBM_DOCLINK_ALLOC_DOC_LINE)) {
+ grown = NULL;
+ } else
+#endif
+ {
+ grown = (doc_line_ent_t *)cbm_arena_alloc(a, (size_t)ncap * sizeof(*grown));
+ }
if (!grown) {
- return; /* the reference keeps its definition's line instead */
+ doc_line_lost(ctx);
+ return;
}
if (m->count > 0) {
memcpy(grown, m->items, (size_t)m->count * sizeof(*grown));
diff --git a/internal/cbm/doclink.h b/internal/cbm/doclink.h
index 3588db1b0..7b85ad45a 100644
--- a/internal/cbm/doclink.h
+++ b/internal/cbm/doclink.h
@@ -149,8 +149,9 @@ enum {
CBM_DOCLINK_ALLOC_TEXT,
CBM_DOCLINK_ALLOC_VALUE,
CBM_DOCLINK_ALLOC_TOKENS,
- CBM_DOCLINK_ALLOC_SCOPE, /* the C# scope scan, as if its builder ran out */
- CBM_DOCLINK_ALLOC_PROJECT, /* the project-file scan, likewise */
+ CBM_DOCLINK_ALLOC_SCOPE, /* the C# scope scan, as if its builder ran out */
+ CBM_DOCLINK_ALLOC_PROJECT, /* the project-file scan, likewise */
+ CBM_DOCLINK_ALLOC_DOC_LINE, /* the doc-line map's growth */
CBM_DOCLINK_ALLOC_KINDS,
};
void cbm_doclink_test_fail_alloc_after(int kind, int nth);
diff --git a/tests/test_doc_mentions.c b/tests/test_doc_mentions.c
index 6e9fe9bf5..dabc7c2ce 100644
--- a/tests/test_doc_mentions.c
+++ b/tests/test_doc_mentions.c
@@ -9775,7 +9775,8 @@ TEST(doc_mentions_incremental_non_ascii_name) {
* loses references, a scope or an edge -- the layer then says error, never
* ok over a silently thinner graph. One allocation fails at each point in
* turn (a doc span, a doc text, a reference value, a token, the scope scan,
- * a MENTIONS edge); the run without a failure has no error row. */
+ * the project scan, the doc-line map, a MENTIONS edge); the run without a
+ * failure has no error row. */
enum { DM_FAIL_EDGE = CBM_DOCLINK_ALLOC_KINDS };
static int dm_alloc_failure_errors(int point) {
@@ -10103,10 +10104,10 @@ TEST(doc_mentions_alloc_failure_status) {
int point;
const char *what;
} points[] = {
- {CBM_DOCLINK_ALLOC_SPAN, "doc span"}, {CBM_DOCLINK_ALLOC_TEXT, "doc text"},
- {CBM_DOCLINK_ALLOC_VALUE, "value"}, {CBM_DOCLINK_ALLOC_TOKENS, "token"},
- {CBM_DOCLINK_ALLOC_SCOPE, "scope scan"}, {CBM_DOCLINK_ALLOC_PROJECT, "project scan"},
- {DM_FAIL_EDGE, "MENTIONS edge"},
+ {CBM_DOCLINK_ALLOC_SPAN, "doc span"}, {CBM_DOCLINK_ALLOC_TEXT, "doc text"},
+ {CBM_DOCLINK_ALLOC_VALUE, "value"}, {CBM_DOCLINK_ALLOC_TOKENS, "token"},
+ {CBM_DOCLINK_ALLOC_SCOPE, "scope scan"}, {CBM_DOCLINK_ALLOC_PROJECT, "project scan"},
+ {CBM_DOCLINK_ALLOC_DOC_LINE, "doc-line map"}, {DM_FAIL_EDGE, "MENTIONS edge"},
};
int baseline = dm_alloc_failure_errors(-1);
bool ok = baseline == 0;