mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-21 10:52:14 +01:00
a1d6da9dfe
This fixes a problem with the Serial UTF-8 decoder. This decoding moves data from char[] buf, into a ByteBuffer inFromSerial, then decodes them into a CharBuffer outToMessage and converts to a char[] to pass on. When the buf read contained just over a full buffer worth of bytes and contained some multi-byte characters, a situation could arise where two decodes were needed to fill up outToMessage, leaving some data in inFromSerial. If in this case no data would be left in buf, decoding would stop until more data came in from serial. This commit fixes this problem by: - Changing the outer loop to continue running when buf is empty, but inFromSerial is not. - Changing the inner loop to run at least once (so it runs when buf is empty, but inFromSerial is no). - Breaking out of the outer loop when no characters were produced (this handles the case where only an incomplete UTF-8 character remains in inFromSerial, which would otherwise prevent the loop from terminating. - Removes a `if (outToMessage.hasRemaining()` check that is now necessarily true if the break was not done. This fixes #9808.