From 0c24e3fde8ac5812573d017fee79c8787852f21d Mon Sep 17 00:00:00 2001 From: Felix Kopp Date: Sat, 14 Nov 2020 04:01:50 +0100 Subject: [PATCH] Fix typos and possible typecast bugs --- include/ardix/ringbuf.h | 2 +- kernel/ringbuf.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/ardix/ringbuf.h b/include/ardix/ringbuf.h index d37aed8..a2cd0bd 100644 --- a/include/ardix/ringbuf.h +++ b/include/ardix/ringbuf.h @@ -18,7 +18,7 @@ struct ringbuf { * @param size: Total buffer size in bytes. * @returns The newly allocated buffer, or `NULL` if OOM. */ -struct ringbuf *rungbuf_create(size_t size); +struct ringbuf *ringbuf_create(size_t size); /** * Destroy a ring buffer previously created with `ringbuf_create`. diff --git a/kernel/ringbuf.c b/kernel/ringbuf.c index 80bedb3..7ee26a0 100644 --- a/kernel/ringbuf.c +++ b/kernel/ringbuf.c @@ -34,26 +34,26 @@ size_t ringbuf_read(uint8_t *dest, struct ringbuf *buf, size_t len) *tmp++ = buf->data[buf->rpos++]; /* wrap around */ - if (buf->rpos = buf->size) + if (buf->rpos == buf->size) buf->rpos = 0; } - return tmp - dest; + return (size_t)tmp - (size_t)dest; } size_t ringbuf_write(struct ringbuf *buf, const uint8_t *src, size_t len) { - uint8_t *tmp = src; + const uint8_t *tmp = src; while (len-- > 0 && buf->wpos != buf->rpos) { buf->data[buf->wpos++] = *tmp++; /* wrap around */ - if (buf->wpos = buf->size) + if (buf->wpos == buf->size) buf->wpos = 0; } - return tmp - src; + return (size_t)tmp - (size_t)src; } size_t ringbuf_size(struct ringbuf *buf)