From 648a5ee51285e5bdc12ae5beb914f7c7cb9485ea Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 25 Sep 2007 06:51:04 +0000 Subject: [PATCH] When we take the difference between two pointers, the result is technically signed. pdiff() makes sure we never get a negative value. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2016 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 3f0638bd..7e9cef55 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -587,3 +587,17 @@ do { \ __func__, __FILE__, __LINE__); \ } while (0); #endif + +/* + * A normal pointer difference is signed, but we never want a negative value + * so this little tool will make sure we don't get that. + */ + +static inline unsigned +pdiff(const void *b, const void *e) +{ + + assert(b <= e); + return + ((unsigned)((const unsigned char *)e - (const unsigned char *)b)); +} -- 2.39.5