Skip to content

Commit 459be8b

Browse files
committed
fix(lsp): build empty cross-registries for zero-def corpora
cbm_arena_alloc(arena, 0) returns NULL, so the java and cs cross-registry builders read a def_count of 0 as OOM and returned NULL — a corpus with no files of that language silently lost its shared registry (and the seal tests caught exactly that: cbm_cs_build_cross_registry(&arena, NULL, 0) == NULL). Guard the partition alloc behind def_count > 0; the empty registry is still built, finalized, and shared. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent ec16764 commit 459be8b

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎internal/cbm/lsp/cs_lsp.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,9 +3714,15 @@ CBMTypeRegistry *cbm_cs_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, i
37143714
* the type buckets exist, then register FUNCS with O(1) lookups, and
37153715
* finalize again to index them. Stable order per phase: overload ties
37163716
* resolve to the first registered QN match. */
3717-
CBMLSPDef *cs = (CBMLSPDef *)cbm_arena_alloc(arena, (size_t)def_count * sizeof(*cs));
3718-
if (!cs)
3719-
return NULL;
3717+
/* def_count == 0 is a valid corpus (no C# files): arena_alloc(0) returns
3718+
* NULL, which must not be mistaken for OOM — the empty registry is still
3719+
* built, finalized, and shared. */
3720+
CBMLSPDef *cs = NULL;
3721+
if (def_count > 0) {
3722+
cs = (CBMLSPDef *)cbm_arena_alloc(arena, (size_t)def_count * sizeof(*cs));
3723+
if (!cs)
3724+
return NULL;
3725+
}
37203726
int total = 0;
37213727
for (int i = 0; i < def_count; i++) {
37223728
if (defs[i].lang == CBM_LANG_CSHARP && cs_def_is_type(&defs[i]))

‎internal/cbm/lsp/java_lsp.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,9 +3846,15 @@ CBMTypeRegistry *cbm_java_build_cross_registry(CBMArena *arena, CBMLSPDef *defs,
38463846
* post-finalize tail stays empty. Bonus over the old one-pass order: a
38473847
* signature can now resolve a type that appears LATER in defs[], the same
38483848
* source-order independence the per-file path already guarantees. */
3849-
CBMLSPDef *jvm = (CBMLSPDef *)cbm_arena_alloc(arena, (size_t)def_count * sizeof(*jvm));
3850-
if (!jvm) {
3851-
return NULL;
3849+
/* def_count == 0 is a valid corpus (no Java files): arena_alloc(0) returns
3850+
* NULL, which must not be mistaken for OOM — the empty registry is still
3851+
* built, finalized, and shared. */
3852+
CBMLSPDef *jvm = NULL;
3853+
if (def_count > 0) {
3854+
jvm = (CBMLSPDef *)cbm_arena_alloc(arena, (size_t)def_count * sizeof(*jvm));
3855+
if (!jvm) {
3856+
return NULL;
3857+
}
38523858
}
38533859
/* Stable two-pass partition: types in defs[] order, then funcs in defs[]
38543860
* order. Func registration order is load-bearing — overload ties resolve

0 commit comments

Comments
 (0)