Cross-join node-only pattern into existing bindings. Returns 0 on success, * CBM_NOT_FOUND when the allocation is refused (overflow) or fails (OOM); the * caller propagates that as a query error rather than silently skipping the * MATCH, which would return a wrong (short) result. */
| 5618 | * caller propagates that as a query error rather than silently skipping the |
| 5619 | * MATCH, which would return a wrong (short) result. */ |
| 5620 | static int cross_join_nodes(binding_t **bindings, int *bind_count, cbm_node_t *extra_nodes, |
| 5621 | int extra_count, const char *nvar, bool opt) { |
| 5622 | size_t alloc_n = 0; |
| 5623 | if (cbm_cypher_cross_join_alloc(*bind_count, extra_count, opt, &alloc_n) != 0) { |
| 5624 | return CBM_NOT_FOUND; /* product overflows int/size_t: fail the query */ |
| 5625 | } |
| 5626 | binding_t *new_bindings = malloc(alloc_n * sizeof(binding_t)); |
| 5627 | if (!new_bindings) { |
| 5628 | return CBM_NOT_FOUND; /* OOM: propagate, don't silently skip the MATCH */ |
| 5629 | } |
| 5630 | size_t new_count = 0; |
| 5631 | for (int bi = 0; bi < *bind_count; bi++) { |
| 5632 | for (int ni = 0; ni < extra_count && new_count < alloc_n; ni++) { |
| 5633 | binding_t nb = {0}; |
| 5634 | binding_copy(&nb, &(*bindings)[bi]); |
| 5635 | binding_set(&nb, nvar, &extra_nodes[ni]); |
| 5636 | new_bindings[new_count++] = nb; |
| 5637 | } |
| 5638 | if (opt && extra_count == 0 && new_count < alloc_n) { |
| 5639 | binding_t nb = {0}; |
| 5640 | binding_copy(&nb, &(*bindings)[bi]); |
| 5641 | new_bindings[new_count++] = nb; |
| 5642 | } |
| 5643 | } |
| 5644 | for (int bi = 0; bi < *bind_count; bi++) { |
| 5645 | binding_free(&(*bindings)[bi]); |
| 5646 | } |
| 5647 | free(*bindings); |
| 5648 | *bindings = new_bindings; |
| 5649 | *bind_count = (int)new_count; /* new_count <= INT_MAX, guaranteed above */ |
| 5650 | return 0; |
| 5651 | } |
| 5652 | |
| 5653 | /* Cross-join pattern-with-rels into existing bindings */ |
| 5654 | static void cross_join_with_rels(cbm_store_t *store, cbm_pattern_t *patn, binding_t **bindings, |
no test coverage detected