[master] 2ce13cf28 Kill redundant redundant null checks
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Feb 6 13:49:09 UTC 2019
commit 2ce13cf28b099bdc56889de15998c237ba25e267
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Feb 21 13:58:17 2017 +0100
Kill redundant redundant null checks
I caught one during a review and figured I might as well sweep the whole
tree, so this patch was created using Coccinelle and the following steps:
$ cat >check_obj.cocci <<EOF
@@
expression obj, magic;
@@
if (obj != NULL) {
- CHECK_OBJ_NOTNULL(obj, magic);
+ CHECK_OBJ(obj, magic);
...
}
EOF
$ spatch --dir . --in-place --sp-file check_obj.cocci
This is my fourth semantic patch, I wouldn't mind checking them in to
have them handy in the repo to semi-automate code polish every now and
then. For example in a /tools/cocci directory. This way people could
study them or use them in their out-of-tree projects like VMODs or VUTs.
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index 8c4d3b538..44b0e4668 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -127,7 +127,7 @@ VDP_close(struct req *req)
if (vdc->retval >= 0)
AN(vdpe);
if (vdpe != NULL) {
- CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
+ CHECK_OBJ(vdpe, VDP_ENTRY_MAGIC);
VTAILQ_REMOVE(&vdc->vdp, vdpe, list);
if (vdpe->vdp->fini != NULL)
AZ(vdpe->vdp->fini(req, &vdpe->priv));
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 7cfa27eeb..afd0d475a 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -503,7 +503,7 @@ VRT_u_bereq_body(VRT_CTX)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
if (ctx->bo->req != NULL) {
- CHECK_OBJ_NOTNULL(ctx->bo->req, REQ_MAGIC);
+ CHECK_OBJ(ctx->bo->req, REQ_MAGIC);
ctx->bo->req = NULL;
ObjSetState(ctx->bo->wrk,
ctx->bo->fetch_objcore, BOS_REQ_DONE);
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index c6eb3a927..c17c80e5d 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -436,7 +436,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
INIT_OBJ(&ctx, VRT_CTX_MAGIC);
if (req != NULL) {
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CHECK_OBJ(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(req->vcl, VCL_MAGIC);
VCL_Req2Ctx(&ctx, req);
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index e6459bc7d..7869f700f 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -413,7 +413,7 @@ VEV_Once(struct vev_root *evb)
tmo = INFTIM;
e = binheap_root(evb->binheap);
if (e != NULL) {
- CHECK_OBJ_NOTNULL(e, VEV_MAGIC);
+ CHECK_OBJ(e, VEV_MAGIC);
assert(e->__binheap_idx == BINHEAP_NOIDX + 1);
t = VTIM_mono();
if (e->__when <= t)
diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c
index a37faec57..e6db240c5 100644
--- a/lib/libvarnishapi/vxp_parse.c
+++ b/lib/libvarnishapi/vxp_parse.c
@@ -629,7 +629,7 @@ vex_print(const struct vex *vex, int indent)
fprintf(stderr, "%*s%s", indent, "", vxp_tnames[vex->tok]);
if (vex->lhs != NULL) {
- CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC);
+ CHECK_OBJ(vex->lhs, VEX_LHS_MAGIC);
AN(vex->lhs->tags);
fprintf(stderr, " lhs=");
if (vex->lhs->level >= 0)
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index e709e9cf0..5360f3aac 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -402,7 +402,7 @@ shard_get_key(VRT_CTX, const struct vmod_directors_shard_param *p)
switch (p->by) {
case BY_HASH:
if (ctx->bo) {
- CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+ CHECK_OBJ(ctx->bo, BUSYOBJ_MAGIC);
return (vbe32dec(ctx->bo->digest));
}
/* FALLTHROUGH */
More information about the varnish-commit
mailing list