]> err.no Git - varnish/commitdiff
When we take the difference between two pointers, the result is technically
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 25 Sep 2007 06:51:04 +0000 (06:51 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 25 Sep 2007 06:51:04 +0000 (06:51 +0000)
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

index 3f0638bd94fdaf8224e5b9bbf6ebb744f8921c2e..7e9cef55fe88b645b5a5cd10cb8d41ddbd24cdc8 100644 (file)
@@ -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));
+}