diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2010-07-15 04:45:31 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2010-07-15 04:45:31 +0000 |
commit | e2e1fe5aad50809f00f6f5258432bd7aa605f47c (patch) | |
tree | d2c55277afd52537fafd198f4755d72ccf5dbc2c /Projects/Benito | |
parent | 7cef08e10e0e7ef770c52dc180b25fdfa5cf758d (diff) | |
download | lufa-e2e1fe5aad50809f00f6f5258432bd7aa605f47c.tar.gz lufa-e2e1fe5aad50809f00f6f5258432bd7aa605f47c.tar.bz2 lufa-e2e1fe5aad50809f00f6f5258432bd7aa605f47c.zip |
Fixed possible buffer overrun in the XPLAINBridge project when in serial bridge mode.
Diffstat (limited to 'Projects/Benito')
-rw-r--r-- | Projects/Benito/Lib/LightweightRingBuff.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Projects/Benito/Lib/LightweightRingBuff.h b/Projects/Benito/Lib/LightweightRingBuff.h index 9c25707b4..0ffe792dc 100644 --- a/Projects/Benito/Lib/LightweightRingBuff.h +++ b/Projects/Benito/Lib/LightweightRingBuff.h @@ -75,6 +75,26 @@ Buffer->Count = 0; } + /** Atomically determines if the specified ring buffer contains any free space. This should + * be tested before storing data to the buffer, to ensure that no data is lost due to a + * buffer overrun. + * + * \param[in,out] Buffer Pointer to a ring buffer structure to insert into + * + * \return Boolean true if the buffer contains no free space, false otherwise + */ + static inline bool RingBuffer_IsFull(RingBuff_t* const Buffer) + { + bool IsFull; + + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + IsFull = (Buffer->Count == BUFFER_SIZE); + } + + return IsFull; + } + /** Atomically inserts an element into the ring buffer. * * \param[in,out] Buffer Pointer to a ring buffer structure to insert into |