[experimental-ims] d763ce0 Tell FlexeLint to check printf-like arguments and fix what it found.
Geoff Simmons
geoff at varnish-cache.org
Mon Jan 9 21:52:48 CET 2012
commit d763ce00fb8599e52b1c06e99b91f257dc1bf822
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Dec 5 22:02:22 2011 +0000
Tell FlexeLint to check printf-like arguments and fix what it found.
Prompted to by: DocWilco
diff --git a/bin/flint.lnt b/bin/flint.lnt
index 4ad63d1..18a8d27 100644
--- a/bin/flint.lnt
+++ b/bin/flint.lnt
@@ -2,6 +2,9 @@
-ffc // No automatic custody
+-printf(2, VSB_printf)
+
+
///////////////////////////////////////////////////////////////////////
// Weirdness relating to varnish includes etc.
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index ca2b616..2badb76 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -77,7 +77,7 @@ struct ban {
unsigned magic;
#define BAN_MAGIC 0x700b08ea
VTAILQ_ENTRY(ban) list;
- unsigned refcount;
+ int refcount;
unsigned flags;
#define BAN_F_GONE (1 << 0)
#define BAN_F_REQ (1 << 2)
@@ -841,7 +841,7 @@ ban_lurker_work(const struct sess *sp, unsigned pass)
break;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (cache_param->diag_bitmap & 0x80000)
- VSL(SLT_Debug, 0, "test: %p %d %d",
+ VSL(SLT_Debug, 0, "test: %p %u %u",
oc, oc->flags & OC_F_LURK, pass);
if ((oc->flags & OC_F_LURK) == pass)
break;
@@ -892,7 +892,7 @@ ban_lurker_work(const struct sess *sp, unsigned pass)
}
Lck_Unlock(&oh->mtx);
if (cache_param->diag_bitmap & 0x80000)
- VSL(SLT_Debug, 0, "lurker done: %p %d %d",
+ VSL(SLT_Debug, 0, "lurker done: %p %u %u",
oc, oc->flags & OC_F_LURK, pass);
(void)HSH_Deref(sp->wrk, NULL, &o);
VTIM_sleep(cache_param->ban_lurker_sleep);
diff --git a/bin/varnishd/cache/cache_cli.c b/bin/varnishd/cache/cache_cli.c
index f299bef..98d89c3 100644
--- a/bin/varnishd/cache/cache_cli.c
+++ b/bin/varnishd/cache/cache_cli.c
@@ -92,7 +92,7 @@ cli_cb_after(const struct cli *cli)
ASSERT_CLI();
Lck_Unlock(&cli_mtx);
- VSL(SLT_CLI, 0, "Wr %03u %u %s",
+ VSL(SLT_CLI, 0, "Wr %03u %zd %s",
cli->result, VSB_len(cli->sb), VSB_data(cli->sb));
}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 6483a99..5da06a7 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -565,7 +565,7 @@ FetchBody(struct worker *w, struct object *obj)
w->busyobj->fetch_obj = NULL;
- WSLB(w, SLT_Fetch_Body, "%u(%s) cls %d mklen %u",
+ WSLB(w, SLT_Fetch_Body, "%u(%s) cls %d mklen %d",
w->busyobj->body_status, body_status(w->busyobj->body_status),
cls, mklen);
@@ -591,7 +591,7 @@ FetchBody(struct worker *w, struct object *obj)
if (cls == 0 && w->busyobj->should_close)
cls = 1;
- WSLB(w, SLT_Length, "%u", obj->len);
+ WSLB(w, SLT_Length, "%zd", obj->len);
{
/* Sanity check fetch methods accounting */
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 784eb28..267af00 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -520,7 +520,7 @@ http_dissect_hdrs(struct worker *w, struct http *hp, unsigned vsl_id, char *p,
if (q - p > htc->maxhdr) {
VSC_C_main->losthdr++;
WSL(w, SLT_LostHeader, vsl_id, "%.*s",
- q - p > 20 ? 20 : q - p, p);
+ (int)(q - p > 20 ? 20 : q - p), p);
return (413);
}
@@ -546,7 +546,7 @@ http_dissect_hdrs(struct worker *w, struct http *hp, unsigned vsl_id, char *p,
} else {
VSC_C_main->losthdr++;
WSL(w, SLT_LostHeader, vsl_id, "%.*s",
- q - p > 20 ? 20 : q - p, p);
+ (int)(q - p > 20 ? 20 : q - p), p);
return (413);
}
}
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index d74e31a..78b5e42 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -114,7 +114,7 @@ Lck__Trylock(struct lock *lck, const char *p, const char *f, int l)
assert(r == 0 || r == EBUSY);
if (cache_param->diag_bitmap & 0x8)
VSL(SLT_Debug, 0,
- "MTX_TRYLOCK(%s,%s,%d,%s) = %d", p, f, l, ilck->w);
+ "MTX_TRYLOCK(%s,%s,%d,%s) = %d", p, f, l, ilck->w, r);
if (r == 0) {
AZ(ilck->held);
ilck->held = 1;
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 923abbd..9fa14e0 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -234,7 +234,7 @@ pan_sess(const struct sess *sp)
VSB_printf(pan_vsp, "sp = %p {\n", sp);
VSB_printf(pan_vsp,
- " fd = %d, id = %d, xid = %u,\n",
+ " fd = %d, id = %u, xid = %u,\n",
sp->fd, sp->vsl_id & VSL_IDENTMASK, sp->xid);
VSB_printf(pan_vsp, " client = %s %s,\n",
sp->addr ? sp->addr : "?.?.?.?",
diff --git a/bin/varnishd/cache/cache_vary.c b/bin/varnishd/cache/cache_vary.c
index 026f937..f55607b 100644
--- a/bin/varnishd/cache/cache_vary.c
+++ b/bin/varnishd/cache/cache_vary.c
@@ -64,7 +64,7 @@ VRY_Create(const struct sess *sp, const struct http *hp)
{
char *v, *p, *q, *h, *e;
struct vsb *sb, *sbh;
- int l;
+ unsigned l;
/* No Vary: header, no worries */
if (!http_GetHdr(hp, H_Vary, &v))
@@ -109,7 +109,7 @@ VRY_Create(const struct sess *sp, const struct http *hp)
e = h;
l = 0xffff;
}
- VSB_printf(sb, "%c%c", (unsigned)l >> 8, l & 0xff);
+ VSB_printf(sb, "%c%c", (int)(l >> 8), (int)(l & 0xff));
/* Append to vary matching string */
VSB_bcat(sb, VSB_data(sbh), VSB_len(sbh));
if (e != h)
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index a0eb4c8..bbf93b5 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -74,7 +74,7 @@ VRT_count(const struct sess *sp, unsigned u)
return;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (cache_param->vcl_trace)
- WSP(sp, SLT_VCL_trace, "%u %d.%d", u,
+ WSP(sp, SLT_VCL_trace, "%u %u.%u", u,
sp->vcl->ref[u].line, sp->vcl->ref[u].pos);
}
@@ -83,7 +83,8 @@ VRT_count(const struct sess *sp, unsigned u)
void
VRT_acl_log(const struct sess *sp, const char *msg)
{
- WSP(sp, SLT_VCL_acl, msg);
+
+ WSP(sp, SLT_VCL_acl, "%s", msg);
}
/*--------------------------------------------------------------------*/
@@ -416,7 +417,7 @@ VRT_synth_page(const struct sess *sp, unsigned flags, const char *str, ...)
SMS_Finish(sp->wrk->obj);
http_Unset(sp->wrk->obj->http, H_Content_Length);
http_PrintfHeader(sp->wrk, sp->vsl_id, sp->wrk->obj->http,
- "Content-Length: %d", sp->wrk->obj->len);
+ "Content-Length: %zd", sp->wrk->obj->len);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index fea5c70..cb54837 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -55,7 +55,7 @@ vrt_do_string(struct worker *w, int fd, const struct http *hp, int fld,
AN(hp);
b = VRT_String(hp->ws, NULL, p, ap);
if (b == NULL || *b == '\0') {
- WSL(w, SLT_LostHeader, fd, err);
+ WSL(w, SLT_LostHeader, fd, "%s", err);
} else {
http_SetH(hp, fld, b);
}
diff --git a/bin/varnishd/cache/cache_wrw.c b/bin/varnishd/cache/cache_wrw.c
index 2160f69..2ffb45e 100644
--- a/bin/varnishd/cache/cache_wrw.c
+++ b/bin/varnishd/cache/cache_wrw.c
@@ -165,7 +165,7 @@ WRW_Flush(struct worker *w)
if (i <= 0) {
wrw->werr++;
WSL(w, SLT_Debug, *wrw->wfd,
- "Write error, retval = %d, len = %d, errno = %s",
+ "Write error, retval = %zd, len = %zd, errno = %s",
i, wrw->liov, strerror(errno));
}
}
diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt
index ec0d955..1942c63 100644
--- a/bin/varnishd/flint.lnt
+++ b/bin/varnishd/flint.lnt
@@ -1,5 +1,11 @@
-d__flexelint_v9__=1
+-printf(3, VSL)
+-printf(4, http_PrintfHeader)
+-printf(4, WSL)
+-printf(3, WSLB)
+-printf(2, VSB_printf)
+
-esym(755, vct_*)
-esym(759, vev_*)
-esym(765, vev_*)
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index 8088509..b67e4ca 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -308,7 +308,7 @@ void vcc_ErrToken(const struct vcc *tl, const struct token *t);
void vcc_ErrWhere(struct vcc *, const struct token *);
void vcc_ErrWhere2(struct vcc *, const struct token *, const struct token *);
-void vcc__Expect(struct vcc *tl, unsigned tok, int line);
+void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line);
int vcc_Teq(const struct token *t1, const struct token *t2);
int vcc_IdIs(const struct token *t, const char *p);
void vcc_ExpectCid(struct vcc *tl);
diff --git a/lib/libvcl/vcc_token.c b/lib/libvcl/vcc_token.c
index 63ebbf3..26f2545 100644
--- a/lib/libvcl/vcc_token.c
+++ b/lib/libvcl/vcc_token.c
@@ -104,7 +104,7 @@ vcc_icoord(struct vsb *vsb, const struct token *t, int tail)
} else
pos++;
}
- VSB_printf(vsb, "('%s' Line %d Pos %d)", t->src->name, lin, pos + 1);
+ VSB_printf(vsb, "('%s' Line %u Pos %u)", t->src->name, lin, pos + 1);
}
/*--------------------------------------------------------------------*/
@@ -261,7 +261,7 @@ vcc_NextToken(struct vcc *tl)
}
void
-vcc__Expect(struct vcc *tl, unsigned tok, int line)
+vcc__Expect(struct vcc *tl, unsigned tok, unsigned line)
{
if (tl->t->tok == tok)
return;
More information about the varnish-commit
mailing list