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 2017/12/29 14:21:51 UTC

[incubator-plc4x] branch master updated: - Fixed a potential bug Justin found (We were incrementing the array one byte too much).

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new a79535d  - Fixed a potential bug Justin found (We were incrementing the array one byte too much).
a79535d is described below

commit a79535d219ad209248bce9beccc737452277897c
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Fri Dec 29 15:21:47 2017 +0100

    - Fixed a potential bug Justin found (We were incrementing the array one byte too much).
---
 .../java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java   | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
index e43c5d4..62df5b5 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
@@ -293,12 +293,12 @@ public class Plc4XS7Protocol extends MessageToMessageCodec<S7Message, PlcRequest
         Class valueType = values[0].getClass();
         if (valueType == Boolean.class) {
             // TODO: Check if this is true and the result is not Math.ceil(values.lenght / 8)
-            result = new byte[values.length * 1];
+            result = new byte[values.length];
             for(int i = 0; i < values.length; i++) {
                 result[i] = (byte) (((Boolean) values[i]) ? 0x01 : 0x00);
             }
         } else if (valueType == Byte[].class) {
-            result = new byte[values.length * 1];
+            result = new byte[values.length];
             for(int i = 0; i < values.length; i++) {
                 result[i] = (byte) values[i];
             }
@@ -354,12 +354,12 @@ public class Plc4XS7Protocol extends MessageToMessageCodec<S7Message, PlcRequest
         return ResponseCode.INTERNAL_ERROR;
     }
 
-    private List<Object> decodeData(Class<?> datatype, byte[] s7Data) {
+    private List<Object> decodeData(Class<?> datatype, byte[] s7Data) throws PlcProtocolException {
         if(s7Data.length == 0) {
             return null;
         }
         List<Object> result = new LinkedList<>();
-        for(int i = 0; i < s7Data.length; i++) {
+        for(int i = 0; i < s7Data.length;) {
             if (datatype == Boolean.class) {
                 result.add((s7Data[i] & 0x01) == 0x01);
                 i+=1;
@@ -381,6 +381,8 @@ public class Plc4XS7Protocol extends MessageToMessageCodec<S7Message, PlcRequest
                     ((s7Data[i + 2] & 0xff) << 8) | (s7Data[i + 3] & 0xff));
                 result.add(Float.intBitsToFloat(intValue));
                 i+=4;
+            } else {
+                throw new PlcProtocolException("Unsupported datatype " + datatype.getSimpleName());
             }
         }
         return result;

-- 
To stop receiving notification emails like this one, please contact
['"commits@plc4x.apache.org" <co...@plc4x.apache.org>'].