Skip to content

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

Closed
@NickBKeenan

Description

@NickBKeenan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions