aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-09-20 14:14:53 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-09-25 22:06:13 +0200
commita7edc7889c6f0a6441bdd5e030125dd795abfd2c (patch)
tree3a2d8ca94bd2fb81147e25ced6c2ec9bc261faf9 /org.eclipse.jgit/src/org/eclipse
parent4cfe27dd0689be2f2cdf8c4e9d2cf4811052915b (diff)
downloadjgit-a7edc7889c6f0a6441bdd5e030125dd795abfd2c.tar.gz
jgit-a7edc7889c6f0a6441bdd5e030125dd795abfd2c.zip
[errorprone] Prevent int expression may overflow
see https://errorprone.info/bugpattern/IntLongMath Change-Id: Id201b7fc49b953d500e88b95e183127fe40ef6cc
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackObjectSizeIndexV1.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java2
7 files changed, 8 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java
index cd7c4e9b39..1ff6e98b12 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java
@@ -348,7 +348,7 @@ public class NameRevCommand extends GitCommand<Map<ObjectId, String>> {
}
// Don't tiebreak if prefixes are the same, in order to prefer first-parent
// paths.
- return li - ri;
+ return (long) li - ri;
}
private static String simplify(String refName) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java
index 45c7b4a475..bedb0b335c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java
@@ -334,7 +334,7 @@ if (k < beginK || k > endK)
abstract boolean meets(int d, int k, int x, long snake);
final long newSnake(int k, int x) {
- long y = k + x;
+ long y = (long) k + x;
long ret = ((long) x) << 32;
return ret | y;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
index 58628a1d47..f72c1eaa8c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
@@ -131,7 +131,7 @@ public class CommitGraphWriter {
chunks = Collections.unmodifiableList(chunks);
long expectedSize = calculateExpectedSize(chunks);
- long writeCount = 256 + 2 * graphCommits.size()
+ long writeCount = 256L + 2 * graphCommits.size()
+ graphCommits.getExtraEdgeCnt();
monitor.beginTask(
MessageFormat.format(JGitText.get().writingOutCommitGraph,
@@ -206,7 +206,7 @@ public class CommitGraphWriter {
private void writeChunkLookup(CancellableDigestOutputStream out,
List<ChunkHeader> chunks) throws IOException {
int numChunks = chunks.size();
- long chunkOffset = 8 + (numChunks + 1) * CHUNK_LOOKUP_WIDTH;
+ long chunkOffset = 8 + (numChunks + 1L) * CHUNK_LOOKUP_WIDTH;
byte[] buffer = new byte[CHUNK_LOOKUP_WIDTH];
for (ChunkHeader chunk : chunks) {
NB.encodeInt32(buffer, 0, chunk.id);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackObjectSizeIndexV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackObjectSizeIndexV1.java
index be2ff67e4f..a3d74be040 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackObjectSizeIndexV1.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackObjectSizeIndexV1.java
@@ -122,7 +122,7 @@ class PackObjectSizeIndexV1 implements PackObjectSizeIndex {
@Override
public long getObjectCount() {
- return positions24.size() + positions32.length;
+ return (long) positions24.size() + positions32.length;
}
@Override
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java
index b86ff7f177..0f71c7fe39 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java
@@ -48,7 +48,7 @@ public class DeltaIndex {
* @return estimated size. Approximately {@code 1.75 * sourceLength}.
*/
public static long estimateIndexSize(int sourceLength) {
- return sourceLength + (sourceLength * 3 / 4);
+ return sourceLength + (sourceLength * 3L / 4);
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java
index 5a18f1e567..8b5cea7af6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java
@@ -97,7 +97,7 @@ class PackWriterBitmapPreparer {
this.distantCommitSpan = config.getBitmapDistantCommitSpan();
this.excessiveBranchCount = config.getBitmapExcessiveBranchCount();
long now = SystemReader.getInstance().getCurrentTime();
- long ageInSeconds = config.getBitmapInactiveBranchAgeInDays()
+ long ageInSeconds = (long) config.getBitmapInactiveBranchAgeInDays()
* DAY_IN_SECONDS;
this.inactiveBranchTimestamp = (now / 1000) - ageInSeconds;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
index 7b4ff7ff16..fea7172d84 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
@@ -133,7 +133,7 @@ public final class NB {
* @since 3.0
*/
public static long decodeInt64(final byte[] intbuf, final int offset) {
- long r = intbuf[offset] << 8;
+ long r = (long) intbuf[offset] << 8;
r |= intbuf[offset + 1] & 0xff;
r <<= 8;