From 454adf55efb8dc2835d1f9dd9c8becb5758657b9 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 24 Dec 2020 16:10:32 +0000 Subject: [PATCH] lws_ptr_diff_size_t lws_ptr_diff() is a very handy helper reducing the pointer delta to an int count of bytes... however many times we actually want a size_t count of bytes since that's the type of the argument we're trying to feed. Let's establish a variant that naturally issues size_t. --- include/libwebsockets/lws-misc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/libwebsockets/lws-misc.h b/include/libwebsockets/lws-misc.h index 0b2df96c1..fe139fee5 100644 --- a/include/libwebsockets/lws-misc.h +++ b/include/libwebsockets/lws-misc.h @@ -186,6 +186,9 @@ lws_buflist_describe(struct lws_buflist **head, void *id, const char *reason); #define lws_ptr_diff(head, tail) \ ((int)((char *)(head) - (char *)(tail))) +#define lws_ptr_diff_size_t(head, tail) \ + ((size_t)(ssize_t)((char *)(head) - (char *)(tail))) + /** * lws_snprintf(): snprintf that truncates the returned length too *