Collections-C icon indicating copy to clipboard operation
Collections-C copied to clipboard

deque_remove_at error

Open yaoture3 opened this issue 3 years ago • 0 comments

Issue repro steps:

  1. Add at least 2 elements with deque_add_first.

  2. Use deque_remove_at to get a element which index greater than 0,your will find element is wrong.

I think the problem is at this sentence 'void *removed = deque->buffer[index];', in which 'index' should be replaced by 'p'.

enum cc_stat deque_remove_at(Deque *deque, size_t index, void **out) { if (index >= deque->size) return CC_ERR_OUT_OF_RANGE;

const size_t c = deque->capacity - 1;
const size_t l = deque->last & c;
const size_t f = deque->first & c;
const size_t p = (deque->first + index) & c;

void *removed  = deque->buffer[index];

if (index == 0)

......

yaoture3 avatar Dec 06 '21 03:12 yaoture3