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

Function check_pattern_var_capacity

src/cypher/cypher.c:6419–6460  ·  view source on GitHub ↗

A binding holds a fixed number of variables: CYP_MAX_VARS node variables and * CYP_MAX_EDGE_VARS edge variables, both in plain arrays (see binding_t). * binding_set and binding_set_edge drop anything past those without a word, so * a query naming more variables than a binding holds cannot be answered — the * extra names bind to nothing and project as empty strings, which reads as * "the graph

Source from the content-addressed store, hash-verified

6417 * and an edge variable may share a name and each take a slot, because the
6418 * binding keeps the two in separate arrays. */
6419static char *check_pattern_var_capacity(const cbm_query_t *q) {
6420 /* Initialized because cppcheck cannot see that scope_holds reads only the
6421 * node_n / edge_n entries already written, and reports the first call as a
6422 * read of an uninitialized array. */
6423 const char *node_vars[CYP_MAX_VARS] = {NULL};
6424 const char *edge_vars[CYP_MAX_EDGE_VARS] = {NULL};
6425 int node_n = 0;
6426 int edge_n = 0;
6427 /* The head of the first pattern always takes a node slot, named or not:
6428 * execute_single binds it under CYP_ANON_HEAD_VAR when the query leaves it
6429 * unnamed. Count it first, or a query with an unnamed head and CYP_MAX_VARS
6430 * named nodes passes this check and still loses its last name in
6431 * binding_set — the exact silence this guard exists to remove. */
6432 if (q->pattern_count > 0 && q->patterns[0].node_count > 0 &&
6433 !q->patterns[0].nodes[0].variable) {
6434 node_vars[node_n++] = CYP_ANON_HEAD_VAR;
6435 }
6436 for (int pi = 0; pi < q->pattern_count; pi++) {
6437 const cbm_pattern_t *pat = &q->patterns[pi];
6438 for (int ni = 0; ni < pat->node_count; ni++) {
6439 const char *var = pat->nodes[ni].variable;
6440 if (!var || scope_holds(node_vars, node_n, var)) {
6441 continue;
6442 }
6443 if (node_n >= CYP_MAX_VARS) {
6444 return var_capacity_error("node", CYP_MAX_VARS);
6445 }
6446 node_vars[node_n++] = var;
6447 }
6448 for (int ri = 0; ri < pat->rel_count; ri++) {
6449 const char *var = pat->rels[ri].variable;
6450 if (!var || scope_holds(edge_vars, edge_n, var)) {
6451 continue;
6452 }
6453 if (edge_n >= CYP_MAX_EDGE_VARS) {
6454 return var_capacity_error("edge", CYP_MAX_EDGE_VARS);
6455 }
6456 edge_vars[edge_n++] = var;
6457 }
6458 }
6459 return NULL;
6460}
6461
6462/* Answers NULL when the query is fine, or a heap message naming the first
6463 * variable that is not in scope. Checks one query; the caller walks a UNION. */

Callers 1

check_projection_scopeFunction · 0.85

Calls 2

scope_holdsFunction · 0.85
var_capacity_errorFunction · 0.85

Tested by

no test coverage detected