From 141108b6eea720bed4de7357d3720e6ccf8850bf Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 16 Jan 2008 11:34:28 +0000 Subject: [PATCH] Introduce the TRUST_ME() macro for voilating the C compilers pointer sensibilities. If only they had done const right... git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2348 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_http.c | 4 ++-- varnish-cache/bin/varnishd/cache_pool.c | 2 +- varnish-cache/bin/varnishd/common.h | 2 ++ varnish-cache/bin/varnishd/shmlog.c | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 6d1b0e3b..256966c3 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -522,8 +522,8 @@ http_SetH(struct http *to, unsigned n, const char *fm) assert(n < HTTP_HDR_MAX); AN(fm); - to->hd[n].b = (void*)(uintptr_t)fm; - to->hd[n].e = (void*)(uintptr_t)strchr(fm, '\0'); + to->hd[n].b = TRUST_ME(fm); + to->hd[n].e = strchr(to->hd[n].b, '\0'); to->hdf[n] = 0; } diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index dba99507..8894ca73 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -135,7 +135,7 @@ WRK_Write(struct worker *w, const void *ptr, int len) len = strlen(ptr); if (w->niov == MAX_IOVS) (void)WRK_Flush(w); - w->iov[w->niov].iov_base = (void*)(uintptr_t)ptr; + w->iov[w->niov].iov_base = TRUST_ME(ptr); w->iov[w->niov].iov_len = len; w->liov += len; w->niov++; diff --git a/varnish-cache/bin/varnishd/common.h b/varnish-cache/bin/varnishd/common.h index 43fd2fbc..dc5f48bf 100644 --- a/varnish-cache/bin/varnishd/common.h +++ b/varnish-cache/bin/varnishd/common.h @@ -44,3 +44,5 @@ extern struct varnish_stats *VSL_stats; void TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen); void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen); int TCP_filter_http(int sock); + +#define TRUST_ME(ptr) ((void*)(uintptr_t)(ptr)) diff --git a/varnish-cache/bin/varnishd/shmlog.c b/varnish-cache/bin/varnishd/shmlog.c index 05ea8844..7799d2bd 100644 --- a/varnish-cache/bin/varnishd/shmlog.c +++ b/varnish-cache/bin/varnishd/shmlog.c @@ -77,7 +77,7 @@ vsl_wrap(void) } static void -vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, int id) +vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, unsigned id) { p[__SHMLOG_LEN_HIGH] = (len >> 8) & 0xff; @@ -142,8 +142,8 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...) va_start(ap, fmt); if (strchr(fmt, '%') == NULL) { - t.b = (void*)(uintptr_t)fmt; - t.e = strchr(fmt, '\0'); + t.b = TRUST_ME(fmt); + t.e = strchr(t.b, '\0'); VSLR(tag, id, t); } else { LOCKSHM(&vsl_mtx); @@ -239,8 +239,8 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) va_start(ap, fmt); if (strchr(fmt, '%') == NULL) { - t.b = (void*)(uintptr_t)fmt; - t.e = strchr(fmt, '\0'); + t.b = TRUST_ME(fmt); + t.e = strchr(t.b, '\0'); WSLR(w, tag, id, t); } else { assert(w->wlp < w->wle); -- 2.39.5