From ea6a3f56d6db5790d826867ede088e455fb837dd Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 29 Sep 2014 13:07:30 +0300 Subject: [PATCH] Fix to bug 487: http://bugs.skysql.com/show_bug.cgi?id=487 Changed all arithmetic operations on raw void pointers to properly use uint8_t pointers instead. --- server/core/buffer.c | 2 +- server/include/buffer.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/core/buffer.c b/server/core/buffer.c index 290da6bde..bee646976 100644 --- a/server/core/buffer.c +++ b/server/core/buffer.c @@ -87,7 +87,7 @@ SHARED_BUF *sbuf; } spinlock_init(&rval->gwbuf_lock); rval->start = sbuf->data; - rval->end = rval->start + size; + rval->end = (void*)((uint8_t*)rval->start + size); sbuf->refcount = 1; rval->sbuf = sbuf; rval->next = NULL; diff --git a/server/include/buffer.h b/server/include/buffer.h index eefdd431d..9ea473b71 100644 --- a/server/include/buffer.h +++ b/server/include/buffer.h @@ -47,6 +47,7 @@ #include #include #include +#include EXTERN_C_BLOCK_BEGIN @@ -150,15 +151,15 @@ typedef struct gwbuf { #define GWBUF_DATA(b) ((b)->start) /*< Number of bytes in the individual buffer */ -#define GWBUF_LENGTH(b) ((b)->end - (b)->start) +#define GWBUF_LENGTH(b) ((unsigned int)(((uint8_t*)(b)->end) - ((uint8_t*)(b)->start))) /*< True if all bytes in the buffer have been consumed */ #define GWBUF_EMPTY(b) ((b)->start == (b)->end) /*< Consume a number of bytes in the buffer */ -#define GWBUF_CONSUME(b, bytes) (b)->start += (bytes) +#define GWBUF_CONSUME(b, bytes) (b)->start = (void*)((uint8_t*)(b)->start + (bytes)) -#define GWBUF_RTRIM(b, bytes) (b)->end -= (bytes) +#define GWBUF_RTRIM(b, bytes) (b)->end = (void*)((uint8_t*)(b)->end - (bytes)) #define GWBUF_TYPE(b) (b)->gwbuf_type /*<