From 40a831a6a70331b06a7d088b09b2a0365cc79fd1 Mon Sep 17 00:00:00 2001 From: Nils Goroll Date: Mon, 5 Jan 2026 12:18:15 +0100 Subject: [PATCH 1/3] Add NO_CHECK_OBJ macro to neuter CHECK_OBJ The CHECK_OBJ*() macros are great, and no-one could ever want to live without them, but they have one disadvantage: They prevent compiler warnings about unused variables. So, for this purpose only, we add NO_CHECK_OBJ to discover more unused variables: $ make CFLAGS='-DNO_CHECK_OBJ -Wall -Werror' ... cache/cache_gzip.c:420:17: error: variable 'wrk' set but not used [-Werror,-Wunused-but-set-variable] struct worker *wrk; --- include/miniobj.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/miniobj.h b/include/miniobj.h index dd6f0ca9d2..c986eb8117 100644 --- a/include/miniobj.h +++ b/include/miniobj.h @@ -57,6 +57,7 @@ #define VALID_OBJ(ptr, type_magic) \ ((ptr) != NULL && (ptr)->magic == (type_magic)) +#ifndef NO_CHECK_OBJ #define CHECK_OBJ(ptr, type_magic) \ do { \ assert((ptr)->magic == type_magic); \ @@ -73,6 +74,11 @@ if ((ptr) != NULL) \ assert((ptr)->magic == type_magic); \ } while (0) +#else +#define CHECK_OBJ(ptr, type_magic) (void)0 +#define CHECK_OBJ_NOTNULL(ptr, type_magic) (void)0 +#define CHECK_OBJ_ORNULL(ptr, type_magic) (void)0 +#endif #define CAST_OBJ(to, from, type_magic) \ do { \ From 33c33dd5c13c03d79fc111e693084f759e4176da Mon Sep 17 00:00:00 2001 From: Nils Goroll Date: Mon, 5 Jan 2026 12:27:10 +0100 Subject: [PATCH 2/3] gc unused variables found using -DNO_CHECK_OBJ --- bin/varnishd/cache/cache_gzip.c | 3 --- bin/varnishd/cache/cache_hash.c | 4 ---- bin/varnishd/cache/cache_session.c | 3 --- bin/varnishd/http2/cache_http2_deliver.c | 3 --- 4 files changed, 13 deletions(-) diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index e7fab9fac1..7e3d245cd9 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -417,12 +417,9 @@ vdp_gunzip_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, enum vgzret_e vr; ssize_t dl; const void *dp; - struct worker *wrk; struct vgz *vg; CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - wrk = vdc->wrk; - CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); (void)act; CAST_OBJ_NOTNULL(vg, *priv, VGZ_MAGIC); diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 23303a60e7..92f8563b3d 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -400,7 +400,6 @@ hsh_vry_match(const struct req *req, struct objcore *oc, const uint8_t *vary) static unsigned hsh_rush_match(const struct req *req) { - struct objhead *oh; struct objcore *oc; oc = req->objcore; @@ -416,9 +415,6 @@ hsh_rush_match(const struct req *req) if (req->vcf != NULL) /* NB: must operate under oh lock. */ return (0); - oh = oc->objhead; - CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - return (hsh_vry_match(req, oc, NULL)); } diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index c031cb665f..de786162b5 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -675,11 +675,8 @@ void SES_Rel(struct sess *sp) { int i; - struct pool *pp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - pp = sp->pool; - CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); Lck_Lock(&sp->mtx); assert(sp->refcnt > 0); diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c index 4013012436..e7ef43fdde 100644 --- a/bin/varnishd/http2/cache_http2_deliver.c +++ b/bin/varnishd/http2/cache_http2_deliver.c @@ -297,7 +297,6 @@ h2_deliver(struct req *req, int sendbody) { size_t sz; const char *r; - struct sess *sp; struct h2_req *r2; struct vsb resp[1]; struct vrt_ctx ctx[1]; @@ -306,8 +305,6 @@ h2_deliver(struct req *req, int sendbody) CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); CAST_OBJ_NOTNULL(r2, req->transport_priv, H2_REQ_MAGIC); - sp = req->sp; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); VSLb(req->vsl, SLT_RespProtocol, "HTTP/2.0"); From e5f3561244bb675dc9bcdbac4a1cb6fc0ff43ad6 Mon Sep 17 00:00:00 2001 From: Nils Goroll Date: Mon, 5 Jan 2026 12:35:39 +0100 Subject: [PATCH 3/3] Polish found using -DNO_CHECK_OBJ --- vmod/vmod_directors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmod/vmod_directors.c b/vmod/vmod_directors.c index 44b98217fe..eed7f60966 100644 --- a/vmod/vmod_directors.c +++ b/vmod/vmod_directors.c @@ -343,7 +343,7 @@ vdir_update_health(VRT_CTX, struct vdir *vd) be = vd->backend[u]; CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); c = 0; - h = VRT_Healthy(ctx, vd->backend[u], &c); + h = VRT_Healthy(ctx, be, &c); if (h) { nh++; tw += vd->weight[u];