Fix write when used with long byte array.

If the byte array allocated is longer then the count passed to the
write method, there will be a buffer overflow exception. Only put
the number of bytes specified by count.

Change-Id: I10ff48d5a5cf3f82c4e4e347326be033db300cdb
This commit is contained in:
Joe Ross
2014-11-16 10:36:44 -08:00
parent 6f4d6ed998
commit ccd64090bb

View File

@@ -378,7 +378,7 @@ public class SerialPort {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer dataToSendBuffer = ByteBuffer.allocateDirect(count);
dataToSendBuffer.put(buffer);
dataToSendBuffer.put(buffer, 0, count);
int retVal = SerialPortJNI.serialWrite(m_port, dataToSendBuffer, count, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return retVal;