]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ringbuf.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / ringbuf.c
index d4efbe05fbf5e13f0dd9b9346c196faafa8ad30d..1c3c3e9753653282478e7880d83c3a853b5ef5e3 100644 (file)
@@ -58,7 +58,7 @@ size_t ringbuf_put(struct ringbuf *buf, const void *data, size_t size)
        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;
@@ -96,13 +96,13 @@ size_t ringbuf_peek(struct ringbuf *buf, size_t offset, void *data, size_t size)
        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;
        }
@@ -115,8 +115,9 @@ size_t ringbuf_copy(struct ringbuf *to, struct ringbuf *from, size_t size)
        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)
@@ -129,5 +130,4 @@ void ringbuf_wipe(struct ringbuf *buf)
 {
        memset(buf->data, 0x00, buf->size);
        ringbuf_reset(buf);
-       buf->empty = true;
 }