summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-03-09 02:32:59 +0300
committerOxore <oxore@protonmail.com>2023-03-09 02:32:59 +0300
commit03c9475bc378171a1018c4e56cc453844ddd2b08 (patch)
treec44a2dcebc60f48569dbd5d0696204df4aed41bd
parente5d10780eff394af075c1e394605fb5c915b3688 (diff)
Rewrite ring buffer loops
Somehow the loops turned out to be infinite.
-rw-r--r--app/platform/stm32f0-gcc/ring_buffer.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/platform/stm32f0-gcc/ring_buffer.h b/app/platform/stm32f0-gcc/ring_buffer.h
index 1a065ef..ae4d99d 100644
--- a/app/platform/stm32f0-gcc/ring_buffer.h
+++ b/app/platform/stm32f0-gcc/ring_buffer.h
@@ -20,7 +20,11 @@ public:
}
constexpr void Push(const UnitType *items, size_t nitems)
{
- if (items) for (; nitems; items++, nitems--) Push(*items);
+ if (items) {
+ for (size_t i = 0; i < nitems; i++) {
+ Push(items[i]);
+ }
+ }
}
constexpr UnitType Pop()
{
@@ -30,7 +34,11 @@ public:
}
constexpr void Pop(UnitType* buf, size_t nitems)
{
- if (buf) for (; nitems; nitems--, buf++) *buf = Pop();
+ if (buf) {
+ for (size_t i = 0; i < nitems; i++) {
+ buf[i] = Pop();
+ }
+ }
}
constexpr size_t Free()
{