Bug in teensy3 HardwareSerial peek helper functions

anakkii

New member
An eensy teensy bug with serial_peek():

I'm looking at the serial[1,2,3].c files in the teensy3 core library. I understand that RX and TX data handling is provided by a pair of ring buffers, where head points to the newest element, and tail points to the byte before the oldest element. However, the peek function is implemented as:

Code:
int serial_peek(void)
{
        ...
	if (head == tail) return -1;
	return rx_buffer[tail];
}

But it looks like it ought to be:

Code:
int serial_peek(void)
{
        ...
	if (head == tail) return -1;
        if (++tail >= RX_BUFFER_SIZE) tail = 0;
	return rx_buffer[tail];
}
 
Yes, you're right, it's a bug. I'll fix this in Teensyduino 1.17.

@mlu - in this case, "tail" is a local copy of the actual tail variable. It does need to be incremented.
 
Back
Top