In SoftwareSerial, the ring buffer is defined as a signed char, which causes corruption #243
Labels
conclusion: resolved
Issue was resolved
topic: code
Related to content of the project itself
type: imperfection
Perceived defect in any part of project
In SoftwareSerial.h the ring buffer is defined as:
ArduinoCore-renesas/libraries/SoftwareSerial/src/SoftwareSerial.h
Line 60 in bba294b
This is a signed quantity. If a byte is received where the high bit is set, this causes unexpected and incorrect behavior.
This is
SoftwareSerial::read()
:ArduinoCore-renesas/libraries/SoftwareSerial/src/SoftwareSerial.cpp
Lines 328 to 335 in bba294b
It returns an
int
, which is a signed quantity. Sinceget()
is returning achar
, which is also a signed quantity, if the highest bit in that byte is set all of the high-order bits in theint
that is returned will be set. Code that checks for the read value to be less than zero will fail.Defining it instead as:
::RingBuffer<uint8_t> ringbuf;
fixes the problem and gives expected behavior.
The text was updated successfully, but these errors were encountered: