You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2020/10/02 11:54:19 UTC
[skywalking] branch master updated: Promote Integer to Long before
multiplying to avoid numeric overflow (#5602)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 0171ff6 Promote Integer to Long before multiplying to avoid numeric overflow (#5602)
0171ff6 is described below
commit 0171ff6a01a3d5bccf6fb96517cd676545f7a0e6
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Fri Oct 2 19:53:48 2020 +0800
Promote Integer to Long before multiplying to avoid numeric overflow (#5602)
---
.../skywalking/apm/commons/datacarrier/buffer/Channels.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java
index 26c7ab0..b9ad4fd 100644
--- a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java
@@ -27,7 +27,7 @@ import org.apache.skywalking.apm.commons.datacarrier.partition.IDataPartitioner;
public class Channels<T> {
private final QueueBuffer<T>[] bufferChannels;
private IDataPartitioner<T> dataPartitioner;
- private BufferStrategy strategy;
+ private final BufferStrategy strategy;
private final long size;
public Channels(int channelSize, int bufferSize, IDataPartitioner<T> partitioner, BufferStrategy strategy) {
@@ -36,12 +36,13 @@ public class Channels<T> {
bufferChannels = new QueueBuffer[channelSize];
for (int i = 0; i < channelSize; i++) {
if (BufferStrategy.BLOCKING.equals(strategy)) {
- bufferChannels[i] = new ArrayBlockingQueueBuffer<T>(bufferSize, strategy);
+ bufferChannels[i] = new ArrayBlockingQueueBuffer<>(bufferSize, strategy);
} else {
- bufferChannels[i] = new Buffer<T>(bufferSize, strategy);
+ bufferChannels[i] = new Buffer<>(bufferSize, strategy);
}
}
- size = channelSize * bufferSize;
+ // noinspection PointlessArithmeticExpression
+ size = 1L * channelSize * bufferSize; // it's not pointless, it prevents numeric overflow before assigning an integer to a long
}
public boolean save(T data) {