diff options
-rw-r--r-- | kern/cbuf.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kern/cbuf.c b/kern/cbuf.c index f00532ef..ea848c56 100644 --- a/kern/cbuf.c +++ b/kern/cbuf.c @@ -99,7 +99,7 @@ cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size) end = start + size; buf_end = cbuf->buf + cbuf->capacity; - if (end > buf_end) { + if ((end <= cbuf->buf) || (end > buf_end)) { skip = buf_end - start; memcpy(start, buf, skip); buf += skip; @@ -133,7 +133,7 @@ cbuf_read(const struct cbuf *cbuf, size_t index, void *buf, size_t *sizep) end = start + *sizep; buf_end = cbuf->buf + cbuf->capacity; - if (end <= buf_end) { + if ((end > cbuf->buf) && (end <= buf_end)) { size = *sizep; } else { size = buf_end - start; |