]> source.dussan.org Git - jgit.git/commitdiff
[errorprone] Prevent int expression may overflow 82/204582/9
authorMatthias Sohn <matthias.sohn@sap.com>
Wed, 20 Sep 2023 12:14:53 +0000 (14:14 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 25 Sep 2023 20:06:13 +0000 (22:06 +0200)
see https://errorprone.info/bugpattern/IntLongMath

Change-Id: Id201b7fc49b953d500e88b95e183127fe40ef6cc

org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantLibrary.java
org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackObjectSizeIndexV1.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java
org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java

index 9a30d804e76437d29e86084de81a28aac5c42678..abfbca4b02fa7989474c82a4b602f4dc190e4dd5 100644 (file)
@@ -137,7 +137,7 @@ public final class PageantLibrary {
                }
 
                private Pointer init(CopyStruct c) {
-                       c.cbData = name.length + 1;
+                       c.cbData = name.length + 1L;
                        c.lpData = new Memory(c.cbData);
                        c.lpData.write(0, name, 0, name.length);
                        c.lpData.setByte(name.length, (byte) 0);
index cd7c4e9b391281ae927e6e3a76f5c21255a5a4df..1ff6e98b12aa44055dd670854c05c7d00059600b 100644 (file)
@@ -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) {
index 45c7b4a4755815aa46861e01a418a43b24a5016e..bedb0b335c24a1fe924cfb274d1cf7611f93fa8b 100644 (file)
@@ -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;
                        }
index 58628a1d47c4844ff2a8b5d94a18f79b752e3cff..f72c1eaa8c977f0e693937be8120c607d6c52282 100644 (file)
@@ -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);
index be2ff67e4f863c4f2fff15bc367d0b9fab8e5a24..a3d74be04021a433272c78b50c8d3a78edd58d09 100644 (file)
@@ -122,7 +122,7 @@ class PackObjectSizeIndexV1 implements PackObjectSizeIndex {
 
        @Override
        public long getObjectCount() {
-               return positions24.size() + positions32.length;
+               return (long) positions24.size() + positions32.length;
        }
 
        @Override
index b86ff7f177a6a32a2c55ee69b5c1be0ce509ebe6..0f71c7fe391e8cf2bbb4a20c6047484e1be51b4b 100644 (file)
@@ -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);
        }
 
        /**
index 5a18f1e5677e9e7b627e6a65119f3078e7f7bdb7..8b5cea7af61c027a770038d93d80c4c75e21de1f 100644 (file)
@@ -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;
        }
index 7b4ff7ff164529aafd55552bca6cd89631cf4757..fea7172d840289f4d7013e6f7de856009aadb8ef 100644 (file)
@@ -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;