Flexelinting

parent 348e7ba0
...@@ -36,3 +36,6 @@ TESTS = @VMOD_TESTS@ ...@@ -36,3 +36,6 @@ TESTS = @VMOD_TESTS@
EXTRA_DIST = \ EXTRA_DIST = \
vmod_weightadjust.vcc \ vmod_weightadjust.vcc \
$(VMOD_TESTS) $(VMOD_TESTS)
flint:
flexelint $(VARNISHAPI_CFLAGS) -I .. flint.lnt *.c
-sem(VAS_Fail, r_no)
-e717 // do ... while(1) ...
-e801 // goto
-e506 // const bool
-e793 // sifnificant characters...
-emacro(747, ALLOC_OBJ) // Significant prototype coercion
-efile(766, config.h)
-e763 // XXX TODO Redudant declaration
//vdir.c
-esym(534, VSB_*)
\ No newline at end of file
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "cache/cache.h" #include "cache/cache.h"
#include "cache/cache_director.h"
#include "vbm.h" #include "vbm.h"
#include "vrnd.h" #include "vrnd.h"
...@@ -43,8 +42,10 @@ ...@@ -43,8 +42,10 @@
#define vmod_directors_random vmod_weightadjust_random #define vmod_directors_random vmod_weightadjust_random
#define VMOD_DIRECTORS_RANDOM_MAGIC VMOD_WEIGHTADJUST_RANDOM_MAGIC #define VMOD_DIRECTORS_RANDOM_MAGIC VMOD_WEIGHTADJUST_RANDOM_MAGIC
//lint -e652 override
#define vmod_random__init _vmod_random__init #define vmod_random__init _vmod_random__init
#define vmod_random__fini _vmod_random__fini #define vmod_random__fini _vmod_random__fini
//lint +e652 override
static VCL_BOOL static VCL_BOOL
vmod_random_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed) vmod_random_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
...@@ -79,7 +80,7 @@ vmod_random_resolve(VRT_CTX, VCL_BACKEND dir) ...@@ -79,7 +80,7 @@ vmod_random_resolve(VRT_CTX, VCL_BACKEND dir)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC); CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
r = scalbn(VRND_RandomTestable(), -31); r = scalbn((double)VRND_RandomTestable(), -31);
assert(r >= 0 && r < 1.0); assert(r >= 0 && r < 1.0);
be = vdir_pick_be(ctx, rr->vd, r); be = vdir_pick_be(ctx, rr->vd, r);
return (be); return (be);
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "cache/cache.h" #include "cache/cache.h"
#include "vbm.h" #include "vbm.h"
#include "vcl.h"
#include "vsb.h" #include "vsb.h"
#include "vdir.h" #include "vdir.h"
...@@ -167,8 +166,8 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur) ...@@ -167,8 +166,8 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur)
VRT_Assign_Backend(&vd->backend[u], NULL); VRT_Assign_Backend(&vd->backend[u], NULL);
vd->total_weight -= vd->weight[u]; vd->total_weight -= vd->weight[u];
n = (vd->n_backend - u) - 1; n = (vd->n_backend - u) - 1;
memmove(&vd->backend[u], &vd->backend[u+1], n * sizeof(vd->backend[0])); memmove(&vd->backend[u], &vd->backend[u]+1, n * sizeof(vd->backend[0]));
memmove(&vd->weight[u], &vd->weight[u+1], n * sizeof(vd->weight[0])); memmove(&vd->weight[u], &vd->weight[u]+1, n * sizeof(vd->weight[0]));
vd->n_backend--; vd->n_backend--;
if (cur) { if (cur) {
...@@ -239,7 +238,7 @@ vdir_list(VRT_CTX, struct vdir *vd, struct vsb *vsb, int pflag, int jflag, ...@@ -239,7 +238,7 @@ vdir_list(VRT_CTX, struct vdir *vd, struct vsb *vsb, int pflag, int jflag,
be = vd->backend[u]; be = vd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
h = vbit_test(vd->healthy, u); h = (typeof(h))vbit_test(vd->healthy, u);
w = h ? vd->weight[u] : 0.0; w = h ? vd->weight[u] : 0.0;
...@@ -331,7 +330,7 @@ vdir_update_health(VRT_CTX, struct vdir *vd) ...@@ -331,7 +330,7 @@ vdir_update_health(VRT_CTX, struct vdir *vd)
} }
if (c > changed) if (c > changed)
changed = c; changed = c;
if (h != vbit_test(healthy, u)) { if (h != (typeof(h))vbit_test(healthy, u)) {
if (h) if (h)
vbit_set(healthy, u); vbit_set(healthy, u);
else else
......
...@@ -37,9 +37,7 @@ ...@@ -37,9 +37,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <poll.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <pcre.h> #include <pcre.h>
...@@ -47,14 +45,8 @@ ...@@ -47,14 +45,8 @@
#include "cache/cache.h" #include "cache/cache.h"
#include "vcl.h" #include "vcl.h"
#include "vre.h"
#include "vsa.h"
#include "vtim.h"
#include "vtcp.h"
#include "vsb.h" #include "vsb.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h" #include "cache/cache_backend.h"
#include "vdir.h" #include "vdir.h"
...@@ -93,7 +85,7 @@ priv_vcl_free(VRT_CTX, void *priv) ...@@ -93,7 +85,7 @@ priv_vcl_free(VRT_CTX, void *priv)
(void)ctx; (void)ctx;
CAST_OBJ_NOTNULL(wa_vcl, priv, VMOD_WADJ_VCL_MAGIC); CAST_OBJ_NOTNULL(wa_vcl, priv, VMOD_WADJ_VCL_MAGIC);
AN(VTAILQ_EMPTY(&wa_vcl->props)); assert(VTAILQ_EMPTY(&wa_vcl->props));
AZ(pthread_mutex_destroy(&wa_vcl->mtx)); AZ(pthread_mutex_destroy(&wa_vcl->mtx));
FREE_OBJ(wa_vcl); FREE_OBJ(wa_vcl);
AZ(wa_vcl); AZ(wa_vcl);
...@@ -115,6 +107,7 @@ vmod_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e) ...@@ -115,6 +107,7 @@ vmod_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
switch (e) { switch (e) {
case VCL_EVENT_LOAD: case VCL_EVENT_LOAD:
ALLOC_OBJ(wa_vcl, VMOD_WADJ_VCL_MAGIC); ALLOC_OBJ(wa_vcl, VMOD_WADJ_VCL_MAGIC);
AN(wa_vcl);
VTAILQ_INIT(&wa_vcl->props); VTAILQ_INIT(&wa_vcl->props);
AZ(pthread_mutex_init(&wa_vcl->mtx, NULL)); AZ(pthread_mutex_init(&wa_vcl->mtx, NULL));
priv->priv = wa_vcl; priv->priv = wa_vcl;
...@@ -138,9 +131,9 @@ vmod_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e) ...@@ -138,9 +131,9 @@ vmod_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
/* largely taken from vbp_build_req() */ /* largely taken from vbp_build_req() */
static char * static char *
wadj_cfg_req(const struct backend *be, VCL_STRING url, VCL_STRING request, wadj_cfg_req(const struct backend *be, VCL_STRING url, VCL_STRING request,
int *len) ssize_t *len)
{ {
const int reql = request ? strlen(request) + 1 : 0; const size_t reql = request ? strlen(request) + 1 : 0;
char s[reql]; char s[reql];
char *ret, *tok, *save; char *ret, *tok, *save;
int c = 0; int c = 0;
...@@ -176,10 +169,12 @@ wadj_cfg_req(const struct backend *be, VCL_STRING url, VCL_STRING request, ...@@ -176,10 +169,12 @@ wadj_cfg_req(const struct backend *be, VCL_STRING url, VCL_STRING request,
ret = strdup(VSB_data(vsb)); ret = strdup(VSB_data(vsb));
AN(ret); AN(ret);
*len = VSB_len(vsb); *len = VSB_len(vsb);
assert(*len >= 0);
VSB_destroy(&vsb); VSB_destroy(&vsb);
return (ret); return (ret);
} }
//lint -e{818} priv
VCL_VOID VCL_VOID
vmod_random__init(VRT_CTX, struct vmod_weightadjust_random **rrp, vmod_random__init(VRT_CTX, struct vmod_weightadjust_random **rrp,
const char *vcl_name, struct vmod_priv *priv) const char *vcl_name, struct vmod_priv *priv)
...@@ -217,6 +212,7 @@ vmod_random__fini(struct vmod_weightadjust_random **rrp) ...@@ -217,6 +212,7 @@ vmod_random__fini(struct vmod_weightadjust_random **rrp)
AZ(rr); AZ(rr);
} }
//lint -e{818} args
VCL_VOID VCL_VOID
vmod_random_add_backend(VRT_CTX, vmod_random_add_backend(VRT_CTX,
struct VPFX(weightadjust_random) *rr, struct VPFX(weightadjust_random) *rr,
...@@ -262,6 +258,7 @@ vmod_random_add_backend(VRT_CTX, ...@@ -262,6 +258,7 @@ vmod_random_add_backend(VRT_CTX,
} }
ALLOC_OBJ(prop, WADJ_PROP_MAGIC); ALLOC_OBJ(prop, WADJ_PROP_MAGIC);
AN(prop);
AZ(pthread_mutex_init(&prop->wakeup.mtx, NULL)); AZ(pthread_mutex_init(&prop->wakeup.mtx, NULL));
AZ(pthread_cond_init(&prop->wakeup.cv, NULL)); AZ(pthread_cond_init(&prop->wakeup.cv, NULL));
prop->vd = rr->vd; prop->vd = rr->vd;
......
...@@ -51,8 +51,6 @@ ...@@ -51,8 +51,6 @@
#include "vtcp.h" #include "vtcp.h"
#include "vrnd.h" #include "vrnd.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h" #include "cache/cache_backend.h"
#ifdef FIXME #ifdef FIXME
#include "cache/cache_tcp_pool.h" #include "cache/cache_tcp_pool.h"
...@@ -82,11 +80,12 @@ int VCP_Open(struct conn_pool *, vtim_dur tmo, VCL_IP *, int*); ...@@ -82,11 +80,12 @@ int VCP_Open(struct conn_pool *, vtim_dur tmo, VCL_IP *, int*);
/* largely copied from vbp_poke */ /* largely copied from vbp_poke */
static void static void
wadj_poke(const struct wadj_prop *prop, char *buf, wadj_poke(const struct wadj_prop *prop, char *buf,
unsigned *len) ssize_t *len)
{ {
int s, tmo, i, err; int s, tmo, err;
ssize_t i;
ssize_t rlen;
double t_start, t_now, t_end; double t_start, t_now, t_end;
unsigned rlen;
struct pollfd pfda[1], *pfd = pfda; struct pollfd pfda[1], *pfd = pfda;
const struct suckaddr *sa; const struct suckaddr *sa;
// pcre JIT requires 32K anyway, and we are not running when it is // pcre JIT requires 32K anyway, and we are not running when it is
...@@ -117,9 +116,10 @@ wadj_poke(const struct wadj_prop *prop, char *buf, ...@@ -117,9 +116,10 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
return; return;
} }
i = write(s, prop->req, prop->reqlen); assert(prop->reqlen >= 0);
i = write(s, prop->req, (size_t)prop->reqlen);
if (i != prop->reqlen) { if (i != prop->reqlen) {
POKE_ERR(prop, "short write (%d out of %d bytes)", POKE_ERR(prop, "short write (%zd out of %zd bytes)",
i, prop->reqlen); i, prop->reqlen);
VTCP_close(&s); VTCP_close(&s);
return; return;
...@@ -132,7 +132,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf, ...@@ -132,7 +132,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
pfd->revents = 0; pfd->revents = 0;
tmo = (int)round((t_end - t_now) * 1e3); tmo = (int)round((t_end - t_now) * 1e3);
if (tmo > 0) if (tmo > 0)
i = poll(pfd, 1, tmo); i = poll(pfd, 1UL, tmo);
if (i == 0 || tmo <= 0) { if (i == 0 || tmo <= 0) {
POKE_ERR(prop, "read timeout after %fs", POKE_ERR(prop, "read timeout after %fs",
VTIM_real() - t_start); VTIM_real() - t_start);
...@@ -140,7 +140,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf, ...@@ -140,7 +140,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
return; return;
} }
if (rlen < prop->bufsz) if (rlen < prop->bufsz)
i = read(s, buf + rlen, prop->bufsz - rlen); i = read(s, buf + rlen, (size_t)(prop->bufsz - rlen));
else else
i = read(s, drain, sizeof(drain)); i = read(s, drain, sizeof(drain));
if (i <= 0) if (i <= 0)
...@@ -155,6 +155,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf, ...@@ -155,6 +155,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
buf[rlen] = '\0'; buf[rlen] = '\0';
else { else {
assert(rlen == prop->bufsz); assert(rlen == prop->bufsz);
assert(rlen > 0);
buf[--rlen] = '\0'; buf[--rlen] = '\0';
} }
...@@ -179,7 +180,7 @@ wadj_update(void *arg) ...@@ -179,7 +180,7 @@ wadj_update(void *arg)
char *p, *pp; char *p, *pp;
AN(pr->bufsz); AN(pr->bufsz);
char buf[pr->bufsz]; char buf[pr->bufsz];
unsigned len; ssize_t len;
double w; double w;
AN(pr->vd); AN(pr->vd);
...@@ -192,7 +193,7 @@ wadj_update(void *arg) ...@@ -192,7 +193,7 @@ wadj_update(void *arg)
POKE_TRACE(pr, "starting"); POKE_TRACE(pr, "starting");
due.tv_sec = (long)VTIM_real(); due.tv_sec = (long)VTIM_real();
due.tv_nsec = 1e9 * VRND_RandomTestableDouble(); due.tv_nsec = (typeof(due.tv_nsec))(1e9 * VRND_RandomTestableDouble());
AZ(pthread_mutex_lock(&wa->mtx)); AZ(pthread_mutex_lock(&wa->mtx));
while (pr->run >= STARTING) { while (pr->run >= STARTING) {
...@@ -201,15 +202,16 @@ wadj_update(void *arg) ...@@ -201,15 +202,16 @@ wadj_update(void *arg)
if (i == 0 || i == EINTR) if (i == 0 || i == EINTR)
continue; continue;
assert(i == ETIMEDOUT); assert(i == ETIMEDOUT);
due.tv_sec += pr->interval; due.tv_sec += (typeof(due.tv_sec))pr->interval;
wadj_poke(pr, buf, &len); wadj_poke(pr, buf, &len);
if (len == 0) if (len == 0)
continue; continue;
assert(len > 0);
assert(len <= pr->bufsz); assert(len <= pr->bufsz);
// XXX should use VRE_MATCH_NOTBOL|VRE_MATCH_NOTEOL // XXX should use VRE_MATCH_NOTBOL|VRE_MATCH_NOTEOL
i = VRE_capture(pr->vre, buf, len, 0 /*here*/, groups, 2, NULL); i = VRE_capture(pr->vre, buf, (size_t)len, 0 /*here*/, groups,
2UL, NULL);
if (i < 0) { if (i < 0) {
POKE_ERR(pr, "regular expression error %d", i); POKE_ERR(pr, "regular expression error %d", i);
...@@ -221,7 +223,6 @@ wadj_update(void *arg) ...@@ -221,7 +223,6 @@ wadj_update(void *arg)
"need one caputuring match, got %d", i - 1); "need one caputuring match, got %d", i - 1);
continue; continue;
} }
groups[1].e = '\0';
p = (char *)groups[1].b; p = (char *)groups[1].b;
errno = 0; errno = 0;
...@@ -268,6 +269,7 @@ static void ...@@ -268,6 +269,7 @@ static void
wadj_thr_start(struct wadj_prop *prop) wadj_thr_start(struct wadj_prop *prop)
{ {
pthread_attr_t attr; pthread_attr_t attr;
size_t sz;
if (prop->run >= STARTING) if (prop->run >= STARTING)
return; return;
...@@ -279,7 +281,9 @@ wadj_thr_start(struct wadj_prop *prop) ...@@ -279,7 +281,9 @@ wadj_thr_start(struct wadj_prop *prop)
} }
AZ(pthread_attr_init(&attr)); AZ(pthread_attr_init(&attr));
// 32K JIT + 32K general + buf // 32K JIT + 32K general + buf
AZ(pthread_attr_setstacksize(&attr, 64 * 1024 + prop->bufsz)); assert(prop->bufsz > 0);
sz = 64 * 1024 + (size_t)prop->bufsz;
AZ(pthread_attr_setstacksize(&attr, sz));
prop->run = STARTING; prop->run = STARTING;
AZ(pthread_create(&prop->thread, &attr, wadj_update, prop)); AZ(pthread_create(&prop->thread, &attr, wadj_update, prop));
...@@ -311,7 +315,7 @@ wadj_thr_stop(struct wadj_prop *prop) ...@@ -311,7 +315,7 @@ wadj_thr_stop(struct wadj_prop *prop)
/* wa_vcl->mtx must be held */ /* wa_vcl->mtx must be held */
void void
wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl, wadj_thr_ctl(const struct vmod_wadj_vcl *wa_vcl,
struct wadj_prop *prop, enum wadj_thr_action_e action) struct wadj_prop *prop, enum wadj_thr_action_e action)
{ {
if (wa_vcl->state == VCL_EVENT_LOAD || if (wa_vcl->state == VCL_EVENT_LOAD ||
...@@ -321,13 +325,15 @@ wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl, ...@@ -321,13 +325,15 @@ wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl,
if (prop) { if (prop) {
if (wa_vcl->state == VCL_EVENT_WARM) { if (wa_vcl->state == VCL_EVENT_WARM) {
if (action == START || action == DEFAULT) if (action == START || action == DEFAULT)
return wadj_thr_start(prop); wadj_thr_start(prop);
else else
return wadj_thr_stop(prop); wadj_thr_stop(prop);
return;
} }
assert(wa_vcl->state == VCL_EVENT_COLD); assert(wa_vcl->state == VCL_EVENT_COLD);
return wadj_thr_stop(prop); wadj_thr_stop(prop);
return;
} }
assert(prop == NULL); assert(prop == NULL);
...@@ -379,6 +385,7 @@ wadj_dir_fini(const struct wadj_prop_head *vd_props, ...@@ -379,6 +385,7 @@ wadj_dir_fini(const struct wadj_prop_head *vd_props,
{ {
struct wadj_prop *prop, *save; struct wadj_prop *prop, *save;
//lint -e{850} loop variable modified
VTAILQ_FOREACH_SAFE(prop, vd_props, list_vd, save) { VTAILQ_FOREACH_SAFE(prop, vd_props, list_vd, save) {
VTAILQ_REMOVE(vcl_props, prop, list_vcl); VTAILQ_REMOVE(vcl_props, prop, list_vcl);
VRT_Assign_Backend(&prop->dir, NULL); VRT_Assign_Backend(&prop->dir, NULL);
......
...@@ -56,7 +56,7 @@ struct wadj_prop { ...@@ -56,7 +56,7 @@ struct wadj_prop {
enum run_state_e run; enum run_state_e run;
VCL_REGEX vre; VCL_REGEX vre;
char *req; char *req;
int reqlen; ssize_t reqlen;
VCL_DURATION timeout; VCL_DURATION timeout;
VCL_DURATION interval; VCL_DURATION interval;
VCL_INT bufsz; VCL_INT bufsz;
...@@ -77,7 +77,7 @@ enum wadj_thr_action_e { ...@@ -77,7 +77,7 @@ enum wadj_thr_action_e {
DEFAULT DEFAULT
}; };
void wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl, void wadj_thr_ctl(const struct vmod_wadj_vcl *wa_vcl,
struct wadj_prop *prop, enum wadj_thr_action_e action); struct wadj_prop *prop, enum wadj_thr_action_e action);
void wadj_dir_fini(const struct wadj_prop_head *vd_props, void wadj_dir_fini(const struct wadj_prop_head *vd_props,
struct wadj_prop_head *vcl_props); struct wadj_prop_head *vcl_props);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment