Skip to content

Commit d61a22c

Browse files
authored
Fixes crashing bug in FixedQueue. (#859)
* Fixes crashing bug in FixedQueue. When there were many noncommit_back() writes, the full() function would still return that there is open space at the end of the queue. This would then cause certian append function to overrun the end of the space. * fix whitespace
1 parent 65870cf commit d61a22c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/freertos_drivers/common/FixedQueue.hxx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,20 @@ public:
6464
/// @return true if there is no entry in the queue.
6565
bool empty() { return size() == 0; }
6666
/// @return true if the queue cannot accept more elements.
67-
bool full() { return size() >= SIZE; }
67+
bool full()
68+
{
69+
auto sz = size();
70+
if (sz >= SIZE)
71+
{
72+
return true;
73+
}
74+
if (sz != 0 && rdIndex_ == wrIndex_)
75+
{
76+
// noncommit members make the queue full.
77+
return true;
78+
}
79+
return false;
80+
}
6881
/// @return the current number of entries in the queue.
6982
size_t size() { return __atomic_load_n(&count_, __ATOMIC_SEQ_CST); }
7083

0 commit comments

Comments
 (0)