From ad03a59f5cab9e853dc024c801b49aa3ef6d33ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Mon, 15 Oct 2012 17:16:30 -0400 Subject: [PATCH] connection: Use uin32_t for circular buffer indexes We rely on well-defined unsigned overflow behaviour so let's make the index fields actually unsigned. Signed ints aren't guaranteed to have the behavior we want (could be either ones or twos complement). --- src/connection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/connection.c b/src/connection.c index 15d264b..b00491e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -44,7 +44,7 @@ struct wl_buffer { char data[4096]; - int head, tail; + uint32_t head, tail; }; #define MASK(i) ((i) & 4095) @@ -70,7 +70,7 @@ union wl_value { static void wl_buffer_put(struct wl_buffer *b, const void *data, size_t count) { - int head, size; + uint32_t head, size; head = MASK(b->head); if (head + count <= sizeof b->data) { @@ -87,7 +87,7 @@ wl_buffer_put(struct wl_buffer *b, const void *data, size_t count) static void wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count) { - int head, tail; + uint32_t head, tail; head = MASK(b->head); tail = MASK(b->tail); @@ -111,7 +111,7 @@ wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count) static void wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count) { - int head, tail; + uint32_t head, tail; head = MASK(b->head); tail = MASK(b->tail); @@ -135,7 +135,7 @@ wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count) static void wl_buffer_copy(struct wl_buffer *b, void *data, size_t count) { - int tail, size; + uint32_t tail, size; tail = MASK(b->tail); if (tail + count <= sizeof b->data) { @@ -147,7 +147,7 @@ wl_buffer_copy(struct wl_buffer *b, void *data, size_t count) } } -static int +static uint32_t wl_buffer_size(struct wl_buffer *b) { return b->head - b->tail; -- 2.7.4