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] +