-
-
Notifications
You must be signed in to change notification settings - Fork 99
Closed
Labels
conclusion: resolvedIssue was resolvedIssue was resolvedtopic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
In SoftwareSerial.h the ring buffer is defined as:
| ::RingBuffer<char> ringbuf; |
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
| int SoftwareSerial::read() | |
| { | |
| int chr = -1; | |
| if (!rx_descr.ringbuf.empty()) { | |
| chr = rx_descr.ringbuf.get(); | |
| } | |
| return chr; | |
| } |
It returns an int, which is a signed quantity. Since get() is returning a char, which is also a signed quantity, if the highest bit in that byte is set all of the high-order bits in the int 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.
Metadata
Metadata
Assignees
Labels
conclusion: resolvedIssue was resolvedIssue was resolvedtopic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project