libobs/util: Fix end_pos when pushing empty circlebuf front

When pushing to the front of an empty circular buffer, it would not
update the end_pos, so end_pos would be left on 0, and it would break
when trying to push to the back after that. The reason why this bug was
never discovered until now is because breakage only happens when pushing
to the front of an empty buffer, then pushing to the back right after
that.
This commit is contained in:
jp9000 2021-12-09 19:35:01 -08:00
parent ca72f890da
commit 96631d580a

View File

@ -173,7 +173,12 @@ static inline void circlebuf_push_front(struct circlebuf *cb, const void *data,
cb->size += size;
circlebuf_ensure_capacity(cb);
if (cb->start_pos < size) {
if (cb->size == size) {
cb->start_pos = 0;
cb->end_pos = size;
memcpy((uint8_t *)cb->data, data, size);
} else if (cb->start_pos < size) {
size_t back_size = size - cb->start_pos;
if (cb->start_pos)
@ -216,7 +221,12 @@ static inline void circlebuf_push_front_zero(struct circlebuf *cb, size_t size)
cb->size += size;
circlebuf_ensure_capacity(cb);
if (cb->start_pos < size) {
if (cb->size == size) {
cb->start_pos = 0;
cb->end_pos = size;
memset((uint8_t *)cb->data, 0, size);
} else if (cb->start_pos < size) {
size_t back_size = size - cb->start_pos;
if (cb->start_pos)