size_t space = ringbuf_space(buf);
size_t copysize = MIN(size, space);
size_t tocopy = copysize;
- if (tocopy > buf->size - buf->end) {
+ if (tocopy >= buf->size - buf->end) {
size_t ts = buf->size - buf->end;
memcpy(buf->data + buf->end, dp, ts);
buf->end = 0;
size_t remain = ringbuf_remain(buf);
if (offset >= remain)
return 0;
- size_t copysize = MAX(MIN(remain - offset, size), (size_t) 0);
+ size_t copysize = MAX(MIN(remain - offset, size), (size_t)0);
size_t tocopy = copysize;
size_t cstart = (buf->start + offset) % buf->size;
if (tocopy >= buf->size - cstart) {
size_t ts = buf->size - cstart;
memcpy(dp, buf->data + cstart, ts);
- buf->start = cstart = 0;
+ cstart = 0;
tocopy -= ts;
dp += ts;
}
size_t tocopy = MIN(ringbuf_space(to), size);
uint8_t *cbuf = XCALLOC(MTYPE_TMP, tocopy);
tocopy = ringbuf_peek(from, 0, cbuf, tocopy);
+ size_t put = ringbuf_put(to, cbuf, tocopy);
XFREE(MTYPE_TMP, cbuf);
- return ringbuf_put(to, cbuf, tocopy);
+ return put;
}
void ringbuf_reset(struct ringbuf *buf)
{
memset(buf->data, 0x00, buf->size);
ringbuf_reset(buf);
- buf->empty = true;
}