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;
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;
}
validate_state(soil, BUFSIZ, BUFSIZ);
assert(soil->start == 0);
- assert(soil->end == BUFSIZ);
+ assert(soil->end == 0);
/* read 15 bytes of garbage */
printf("Validating read...\n");
validate_state(soil, BUFSIZ, BUFSIZ - 15);
assert(soil->start == 15);
- assert(soil->end == BUFSIZ);
+ assert(soil->end == 0);
/* put another 10 bytes and validate wraparound */
printf("Validating wraparound...\n");