You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/02/21 12:59:28 UTC
[incubator-plc4x] branch develop updated: PLC4X-82 -
java.lang.IndexOutOfBoundsException
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 9410ae3 PLC4X-82 - java.lang.IndexOutOfBoundsException
9410ae3 is described below
commit 9410ae3246404efafbabd296c39ebd05b6323901
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Feb 21 13:59:23 2019 +0100
PLC4X-82 - java.lang.IndexOutOfBoundsException
- Fixed a bug in the DefaultS7MessageProcessor which didn't correctly merge together split up items
---
.../strategies/DefaultS7MessageProcessor.java | 42 +++++++++-------------
1 file changed, 17 insertions(+), 25 deletions(-)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/strategies/DefaultS7MessageProcessor.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/strategies/DefaultS7MessageProcessor.java
index 41db08a..a89bd93 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/strategies/DefaultS7MessageProcessor.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/strategies/DefaultS7MessageProcessor.java
@@ -405,36 +405,28 @@ public class DefaultS7MessageProcessor implements S7MessageProcessor {
if(requestItem.getNumElements() != responseParameterItem.getNumElements()) {
int itemSizeInBytes = requestItem.getDataType().getSizeInBytes();
int totalSizeInBytes = requestItem.getNumElements() * itemSizeInBytes;
- byte[] data = null;
if(varParameter.getType() == ParameterType.READ_VAR) {
- data = new byte[totalSizeInBytes];
+ byte[] data = new byte[totalSizeInBytes];
System.arraycopy(responsePayloadItem.getData(), 0, data, 0, responsePayloadItem.getData().length);
- }
- // Initialize the current size, this will be lower than the original, as the only
- // way to have different count, is if the request was split up.
- int curSizeInBytes = requestItem.getNumElements() * itemSizeInBytes;
-
- // Now iterate over the succeeding pairs of parameters and payloads till we have
- // found the original number of elements.
- while(curSizeInBytes < totalSizeInBytes) {
- responseOffset++;
- // No need to process the parameters, we only need them to get the number of items.
- responseParameterItem = (S7AnyVarParameterItem) parameterItems.get(i + responseOffset);
- curSizeInBytes += responseParameterItem.getNumElements() * itemSizeInBytes;
-
- // Get the next payload item in the list.
- responsePayloadItem = payloadItems.get(i + responseOffset);
-
- // Copy the data of this item behind the previous content.
- if(varParameter.getType() == ParameterType.READ_VAR) {
- System.arraycopy(responsePayloadItem.getData(), 0, data, dataOffset, responsePayloadItem.getData().length);
- dataOffset += responsePayloadItem.getData().length;
+ // Now iterate over the succeeding pairs of parameters and payloads till we have
+ // found the original number of elements.
+ while (dataOffset < totalSizeInBytes) {
+ responseOffset++;
+
+ // Get the next payload item in the list.
+ responsePayloadItem = payloadItems.get(i + responseOffset);
+
+ // Copy the data of this item behind the previous content.
+ if (varParameter.getType() == ParameterType.READ_VAR) {
+ System.arraycopy(responsePayloadItem.getData(), 0, data, dataOffset, responsePayloadItem.getData().length);
+ dataOffset += responsePayloadItem.getData().length;
+ }
}
- }
- mergedPayloadItems.add(new VarPayloadItem(DataTransportErrorCode.OK,
- responsePayloadItem.getDataTransportSize(), data));
+ mergedPayloadItems.add(new VarPayloadItem(DataTransportErrorCode.OK,
+ responsePayloadItem.getDataTransportSize(), data));
+ }
} else {
mergedPayloadItems.add(responsePayloadItem);
}