Skip to content

Commit f3aa5f2

Browse files
Fix race condition in SoftwareSerial::overflow()
If an interrupt causing overflow would occur between reading _buffer_overflow and clearing it, this overflow condition would be immediately cleared and never be returned by overflow(). By only clearing the overflow flag if an overflow actually occurred, this problem goes away (worst case overflow() returns false even though an overflow _just_ occurred, but then the next call to overflow() will return true).
1 parent b1de3e6 commit f3aa5f2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SoftwareSerial : public Stream
8888
void end();
8989
bool isListening() { return this == active_object; }
9090
bool stopListening();
91-
bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
91+
bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; }
9292
int peek();
9393

9494
virtual size_t write(uint8_t byte);

0 commit comments

Comments
 (0)