aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2013-06-13 09:56:46 +0200
committerMatthijs Kooijman <matthijs@stdin.nl>2015-01-26 17:03:25 +0100
commit11ade32f20ce2779d99981947eac6b5c4e52f408 (patch)
tree4979a69826a0e3e55937e22f508ad4d0817a2655
parentcb36793486dd8d8d91c16984c423dbad4f4710a6 (diff)
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).
-rw-r--r--libraries/SoftwareSerial/SoftwareSerial.h2
1 files changed, 1 insertions, 1 deletions
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);