Skip to content

In SoftwareSerial, the ring buffer is defined as a signed char, which causes corruption #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NickBKeenan opened this issue Jan 17, 2024 · 0 comments · Fixed by #314
Closed
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@NickBKeenan
Copy link

NickBKeenan commented Jan 17, 2024

In SoftwareSerial.h the ring buffer is defined as:

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():

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.

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jan 17, 2024
iabdalkader added a commit to iabdalkader/ArduinoCore-renesas that referenced this issue May 13, 2024
iabdalkader added a commit to iabdalkader/ArduinoCore-renesas that referenced this issue May 13, 2024
@per1234 per1234 added the conclusion: resolved Issue was resolved label May 13, 2024
delta-G pushed a commit to delta-G/ArduinoCore-renesas that referenced this issue Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants