mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-11 13:29:49 -05:00
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).
This commit is contained in:
parent
a9dd3badb5
commit
ad03a59f5c
1 changed files with 6 additions and 6 deletions
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
struct wl_buffer {
|
struct wl_buffer {
|
||||||
char data[4096];
|
char data[4096];
|
||||||
int head, tail;
|
uint32_t head, tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MASK(i) ((i) & 4095)
|
#define MASK(i) ((i) & 4095)
|
||||||
|
|
@ -70,7 +70,7 @@ union wl_value {
|
||||||
static void
|
static void
|
||||||
wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
|
wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
|
||||||
{
|
{
|
||||||
int head, size;
|
uint32_t head, size;
|
||||||
|
|
||||||
head = MASK(b->head);
|
head = MASK(b->head);
|
||||||
if (head + count <= sizeof b->data) {
|
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
|
static void
|
||||||
wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
||||||
{
|
{
|
||||||
int head, tail;
|
uint32_t head, tail;
|
||||||
|
|
||||||
head = MASK(b->head);
|
head = MASK(b->head);
|
||||||
tail = MASK(b->tail);
|
tail = MASK(b->tail);
|
||||||
|
|
@ -111,7 +111,7 @@ wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
||||||
static void
|
static void
|
||||||
wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
||||||
{
|
{
|
||||||
int head, tail;
|
uint32_t head, tail;
|
||||||
|
|
||||||
head = MASK(b->head);
|
head = MASK(b->head);
|
||||||
tail = MASK(b->tail);
|
tail = MASK(b->tail);
|
||||||
|
|
@ -135,7 +135,7 @@ wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
||||||
static void
|
static void
|
||||||
wl_buffer_copy(struct wl_buffer *b, void *data, size_t count)
|
wl_buffer_copy(struct wl_buffer *b, void *data, size_t count)
|
||||||
{
|
{
|
||||||
int tail, size;
|
uint32_t tail, size;
|
||||||
|
|
||||||
tail = MASK(b->tail);
|
tail = MASK(b->tail);
|
||||||
if (tail + count <= sizeof b->data) {
|
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)
|
wl_buffer_size(struct wl_buffer *b)
|
||||||
{
|
{
|
||||||
return b->head - b->tail;
|
return b->head - b->tail;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue