aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Schumacher2010-07-09 15:53:57 -0400
committerJeff Schumacher2010-07-12 15:24:42 -0400
commit4c14b7869d47a28aca29e219a3bae10f43083b33 (patch)
tree1efd65612f486c82b312881c58f9cbcbed8309ff
parent64b9458640bafadc70028c99bb038480309e568d (diff)
downloadjgit-4c14b7869d47a28aca29e219a3bae10f43083b33.zip
jgit-4c14b7869d47a28aca29e219a3bae10f43083b33.tar.gz
jgit-4c14b7869d47a28aca29e219a3bae10f43083b33.tar.xz
Fixed potential div by zero bug
The scoring logic in SimilarityIndex was dividing by the max file size. If both files are empty, this would cause a div by zero error. This case cannot currently happen, since two empty files would have the same SHA1, and would therefore be caught in the earlier SHA1 based detection pass. Still, if this logic eventually gets separated from that pass, a div by zero error would occur. I changed the logic to instead consider two empty files to have a similarity score of 100. Change-Id: Ic08e18a066b8fef25bb5e7c62418106a8cee762a
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java2
1 files changed, 2 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
index d6026b5..f4cccfc 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
@@ -144,6 +144,8 @@ class SimilarityIndex {
int score(SimilarityIndex dst) {
long max = Math.max(fileSize, dst.fileSize);
+ if (max == 0)
+ return 100;
return (int) ((common(dst) * 100L) / max);
}