From f3aa5f23c4b73028bb7403dc90469571eef5cc59 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 13 Jun 2013 09:56:46 +0200 Subject: [PATCH] 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). --- hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h b/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h index e0e4746cd..27c0bfca9 100644 --- a/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h +++ b/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h @@ -88,7 +88,7 @@ public: void end(); bool isListening() { return this == active_object; } bool stopListening(); - bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; } + bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; } int peek(); virtual size_t write(uint8_t byte);