Fix typos and possible typecast bugs

This commit is contained in:
Felix Kopp 2020-11-14 04:01:50 +01:00
parent 2778fad339
commit 0c24e3fde8
No known key found for this signature in database
GPG key ID: C478BA0A85F75728
2 changed files with 6 additions and 6 deletions

View file

@ -18,7 +18,7 @@ struct ringbuf {
* @param size: Total buffer size in bytes. * @param size: Total buffer size in bytes.
* @returns The newly allocated buffer, or `NULL` if OOM. * @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`. * Destroy a ring buffer previously created with `ringbuf_create`.

View file

@ -34,26 +34,26 @@ size_t ringbuf_read(uint8_t *dest, struct ringbuf *buf, size_t len)
*tmp++ = buf->data[buf->rpos++]; *tmp++ = buf->data[buf->rpos++];
/* wrap around */ /* wrap around */
if (buf->rpos = buf->size) if (buf->rpos == buf->size)
buf->rpos = 0; 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) 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) { while (len-- > 0 && buf->wpos != buf->rpos) {
buf->data[buf->wpos++] = *tmp++; buf->data[buf->wpos++] = *tmp++;
/* wrap around */ /* wrap around */
if (buf->wpos = buf->size) if (buf->wpos == buf->size)
buf->wpos = 0; buf->wpos = 0;
} }
return tmp - src; return (size_t)tmp - (size_t)src;
} }
size_t ringbuf_size(struct ringbuf *buf) size_t ringbuf_size(struct ringbuf *buf)