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

Function cbm_cypher_cross_join_alloc

src/cypher/cypher.c:4533–4545  ·  view source on GitHub ↗

Worst-case binding_t slot count for a node cross-join: one row per * (existing binding × extra node), plus — for an OPTIONAL join with no extra * nodes — one fallback row per existing binding, plus a trailing sentinel slot. * * The plain-int product bind_count * extra_count overflows to a negative/garbage * malloc size on large graphs (the failure mode fixed for cross_join_with_rels), * so t

Source from the content-addressed store, hash-verified

4531 * *out_n on success, CBM_NOT_FOUND on overflow. Non-static so the arithmetic
4532 * boundary can be unit-tested directly. */
4533int cbm_cypher_cross_join_alloc(int bind_count, int extra_count, bool opt, size_t *out_n) {
4534 size_t per_binding = extra_count > 0 ? (size_t)extra_count : (opt ? (size_t)SKIP_ONE : 0U);
4535 size_t rows = (size_t)bind_count * per_binding;
4536 if (rows > (size_t)INT_MAX) {
4537 return CBM_NOT_FOUND; /* new_count would not fit the int binding counter */
4538 }
4539 size_t n = rows + SKIP_ONE;
4540 if (n > SIZE_MAX / sizeof(binding_t)) {
4541 return CBM_NOT_FOUND; /* alloc_n * sizeof(binding_t) would overflow size_t */
4542 }
4543 *out_n = n;
4544 return 0;
4545}
4546
4547/* Cross-join node-only pattern into existing bindings. Returns 0 on success,
4548 * CBM_NOT_FOUND when the allocation is refused (overflow) or fails (OOM); the

Callers 2

cross_join_nodesFunction · 0.85
test_cypher.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected