Skip to content

Commit 943f418

Browse files
committed
fix: Fix a linear space calculation bug
This fixes a bug where the linear space until the end of the buffer was not calculated correctly which would cause data corruption.
1 parent 3e1c9d8 commit 943f418

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lfbb/src/lfbb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ uint8_t *LFBB_WriteAcquire(LFBB_Inst_Type *inst, const size_t free_required) {
8282
const size_t size = inst->size;
8383

8484
const size_t free = CalcFree(w, r, size);
85-
const size_t linear_space = size - r;
85+
const size_t linear_space = size - w;
8686
const size_t linear_free = MIN(free, linear_space);
8787

8888
/* Try to find enough linear space until the end of the buffer */
@@ -116,6 +116,7 @@ void LFBB_WriteRelease(LFBB_Inst_Type *inst, const size_t written) {
116116
}
117117

118118
/* Increment the write index */
119+
assert(w + written <= inst->size);
119120
w += written;
120121

121122
/* If we wrote over invalidated parts of the buffer move the invalidate

0 commit comments

Comments
 (0)