From 11ade32f20ce2779d99981947eac6b5c4e52f408 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 13 Jun 2013 09:56:46 +0200 Subject: 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). --- libraries/SoftwareSerial/SoftwareSerial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index e0e4746..27c0bfc 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/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); -- cgit v1.2.3-18-g5258