From 9c1160ca2cd1626360e2af3f4632bf742dc02824 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Wed, 28 Oct 2020 16:48:54 +0100 Subject: [PATCH] Fixed bad allocation --- src/main/java/Main/ProtocolMessage.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main/ProtocolMessage.java b/src/main/java/Main/ProtocolMessage.java index 934365b..fca8530 100644 --- a/src/main/java/Main/ProtocolMessage.java +++ b/src/main/java/Main/ProtocolMessage.java @@ -50,10 +50,16 @@ public class ProtocolMessage { private void deconstructPacket(char[] raw){ byte[] rawLength = new byte[4]; - System.arraycopy(raw, 0, rawLength, 0, 4); - System.arraycopy(raw, 4, this.message, 0, message.length); + rawLength[0] = (byte)raw[0]; + rawLength[1] = (byte)raw[1]; + rawLength[2] = (byte)raw[2]; + rawLength[3] = (byte)raw[3]; this.length = byteToInt(rawLength); + + this.message = new char[length]; + System.arraycopy(raw, 4, this.message, 0, message.length); + } public int getLength() {