Skip to content

Commit ab43e75

Browse files
authored
Merge pull request DeusData#1476 from DeusData/test/1367-empty-graph-regression
test(similarity): cover the empty-graph qsort null base (DeusData#1367)
2 parents d585d82 + 6a343a7 commit ab43e75

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎tests/test_simhash.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,45 @@ TEST(pass_similarity_short_funcs_skipped) {
803803
PASS();
804804
}
805805

806+
TEST(pass_similarity_empty_graph_no_entries) {
807+
/* Zero Function/Method nodes → the entry array is never allocated. The
808+
* collect phase must not hand that null base to qsort: glibc declares qsort
809+
* nonnull, so passing NULL is UB even at count 0 (#1367).
810+
*
811+
* WHERE THIS BINDS — read before "verifying" it. Remove the count > 1 guard
812+
* in collect_fp_entries and this test still PASSES on macOS (Apple libc does
813+
* not mark qsort nonnull) and on an ordinary Linux ASan/UBSan build, which
814+
* merely prints "null pointer passed as argument 1" and keeps going. It goes
815+
* RED only where UBSan TRAPS (-fno-sanitize-recover), where the process
816+
* aborts and the runner exits 1. Measured both ways on ubuntu-arm64:
817+
* recovering lane = 25 passed with AND without the guard; trapping lane =
818+
* exit 1 without it, 25 passed with it.
819+
*
820+
* The assertions below are therefore the behavioural half (an empty graph
821+
* yields rc 0 and no SIMILAR_TO edges); the UB half is caught by the
822+
* trap-UBSan leg alone. Do not read a green recovering-lane run as proof
823+
* that the null-base guard is still in place. */
824+
cbm_gbuf_t *gb = cbm_gbuf_new("test", "/tmp");
825+
826+
atomic_int cancelled = 0;
827+
cbm_pipeline_ctx_t ctx = {
828+
.project_name = "test",
829+
.repo_path = "/tmp",
830+
.gbuf = gb,
831+
.registry = NULL,
832+
.cancelled = &cancelled,
833+
};
834+
835+
int rc = cbm_pipeline_pass_similarity(&ctx);
836+
ASSERT_EQ(rc, 0);
837+
838+
int sim_count = count_similar_to_edges(gb);
839+
ASSERT_EQ(sim_count, 0);
840+
841+
cbm_gbuf_free(gb);
842+
PASS();
843+
}
844+
806845
/* ═══════════════════════════════════════════════════════════════════
807846
* Suite 4: Full Pipeline Integration (generated test project)
808847
* ═══════════════════════════════════════════════════════════════════ */
@@ -1165,6 +1204,7 @@ SUITE(simhash) {
11651204
RUN_TEST(pass_similarity_edge_properties);
11661205
RUN_TEST(pass_similarity_max_edges_cap);
11671206
RUN_TEST(pass_similarity_short_funcs_skipped);
1207+
RUN_TEST(pass_similarity_empty_graph_no_entries);
11681208

11691209
/* Suite 4: Full Pipeline Integration */
11701210
RUN_TEST(pipeline_minhash_end_to_end);

0 commit comments

Comments
 (0)