Преглед на файлове

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
tags/v0.9.1
Jeff Schumacher преди 14 години
родител
ревизия
4c14b7869d
променени са 1 файла, в които са добавени 2 реда и са изтрити 0 реда
  1. 2
    0
      org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java

+ 2
- 0
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);
}


Loading…
Отказ
Запис