From 59111adb10691bb2afa6e53259b6835053ef5b73 Mon Sep 17 00:00:00 2001 From: Zunnoor Fayyaz Awan Date: Mon, 14 Sep 2026 09:30:57 +0000 Subject: [PATCH] Fix similarity score for binaries without flow graph edges When neither binary has any flow graph edges, the edge term of the program similarity score evaluated to 0, capping the score at 0.65 even for a self-diff. Instead, treat this as full match, since there is no disagreement. Fixes #90 --- differ.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/differ.cc b/differ.cc index 9fcabbd4..e23f0b26 100644 --- a/differ.cc +++ b/differ.cc @@ -550,11 +550,17 @@ double GetSimilarityScore(const CallGraph& call_graph1, const CallGraph& call_graph2, const Histogram& histogram, const Counts& counts) { double similarity = 0; - similarity += - 0.35 * counts[Counts::kFlowGraphEdgeMatchesNonLibrary] / - (std::max(1.0, - 0.5 * (counts[Counts::kFlowGraphEdgesPrimaryNonLibrary] + - counts[Counts::kFlowGraphEdgesSecondaryNonLibrary]))); + const int edges_primary = counts[Counts::kFlowGraphEdgesPrimaryNonLibrary]; + const int edges_secondary = + counts[Counts::kFlowGraphEdgesSecondaryNonLibrary]; + if (edges_primary == 0 && edges_secondary == 0) { + // When neither side has any flow graph edges, there is nothing to disagree + // about, and the edge term is a full match. + similarity += 0.35; + } else { + similarity += 0.35 * counts[Counts::kFlowGraphEdgeMatchesNonLibrary] / + (std::max(1.0, 0.5 * (edges_primary + edges_secondary))); + } similarity += 0.25 * counts[Counts::kBasicBlockMatchesNonLibrary] / (std::max(1.0, 0.5 * (counts[Counts::kBasicBlocksPrimaryNonLibrary] +