aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-01-16 21:58:56 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2023-01-31 14:15:53 +0100
commit611412a05528ba5898cf948f4d3959f1fbc4170a (patch)
tree8cb5e2f67a265feb0af05d107ddfe92860d3a91f /org.eclipse.jgit
parentcd3fc7a2995c06cf2425f51758094e039c938559 (diff)
downloadjgit-611412a05528ba5898cf948f4d3959f1fbc4170a.tar.gz
jgit-611412a05528ba5898cf948f4d3959f1fbc4170a.zip
BatchingProgressMonitor: avoid int overflow when computing percentage
When cloning huge repositories I observed percentage of object counts turning negative. This happened if lastWork * 100 exceeded Integer.MAX_VALUE. Change-Id: Ic5f5cf5a911a91338267aace4daba4b873ab3900
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java6
1 files changed, 3 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
index 2caefa4d97..49e295aed8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
@@ -176,7 +176,7 @@ public abstract class BatchingProgressMonitor implements ProgressMonitor {
}
} else {
// Display once per second or when 1% is done.
- int currPercent = lastWork * 100 / totalWork;
+ int currPercent = Math.round(lastWork * 100F / totalWork);
if (display) {
pm.onUpdate(taskName, lastWork, totalWork, currPercent);
output = true;
@@ -201,8 +201,8 @@ public abstract class BatchingProgressMonitor implements ProgressMonitor {
if (totalWork == UNKNOWN) {
pm.onEndTask(taskName, lastWork);
} else {
- int pDone = lastWork * 100 / totalWork;
- pm.onEndTask(taskName, lastWork, totalWork, pDone);
+ int currPercent = Math.round(lastWork * 100F / totalWork);
+ pm.onEndTask(taskName, lastWork, totalWork, currPercent);
}
}
if (timerFuture != null)