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.

fix(similarity): skip empty fingerprint sort

wargloom5178cde662b2
diff --git a/src/pipeline/pass_similarity.c b/src/pipeline/pass_similarity.c
index 2985dfb95..db4297202 100644
--- a/src/pipeline/pass_similarity.c
+++ b/src/pipeline/pass_similarity.c
@@ -148,8 +148,12 @@ static int collect_fp_entries(cbm_gbuf_t *gbuf, fp_entry_t **out_entries) {
};
}
}
- /* Canonicalize (determinism) — see cmp_fp_entry_by_qn. */
- qsort(entries, (size_t)count, sizeof(fp_entry_t), cmp_fp_entry_by_qn);
+ /* Canonicalize (determinism) — see cmp_fp_entry_by_qn. Avoid passing the
+ * NULL empty-set buffer to qsort: libc treats zero elements as a no-op,
+ * but the standard function contract still requires a valid base pointer. */
+ if (count > 1) {
+ qsort(entries, (size_t)count, sizeof(fp_entry_t), cmp_fp_entry_by_qn);
+ }
*out_entries = entries;
return count;
}