From aca4214c91399f4cae79751ad7a36e3880fff0bf Mon Sep 17 00:00:00 2001 From: James Devine Date: Wed, 23 Jan 2019 20:47:30 +0000 Subject: [PATCH] Reverse ordering of condition check [MicroBitSerial.cpp] A byte would be read and then dropped if bufferIndex >= bufferLen. Reversing the condition check fixes this bug. --- source/drivers/MicroBitSerial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/drivers/MicroBitSerial.cpp b/source/drivers/MicroBitSerial.cpp index 7fad4e00..7ac52cd0 100644 --- a/source/drivers/MicroBitSerial.cpp +++ b/source/drivers/MicroBitSerial.cpp @@ -646,7 +646,7 @@ int MicroBitSerial::read(uint8_t *buffer, int bufferLen, MicroBitSerialMode mode if(mode == ASYNC) { - while((temp = getChar(mode)) != MICROBIT_NO_DATA && bufferIndex < bufferLen) + while(bufferIndex < bufferLen && (temp = getChar(mode)) != MICROBIT_NO_DATA) { buffer[bufferIndex] = (char)temp; bufferIndex++;