Add flexelint recipie and basic flexelinting

parent 1b7b6bd8
......@@ -87,3 +87,8 @@ CLEANFILES = \
clean-local:
@rm -rf $(builddir)/coverage
.PHONY: flint
flint:
flexelint $(VARNISHAPI_CFLAGS) -I .. flint.lnt *.c
-e717 // do ... while(1) ...
-emacro(50, VRBT_*) // Attempted to take the address of a non-lvalue
-emacro(506, VRBT_*) // Constant value Boolean
-emacro(740, VRBT_*) // unusual pointer cast
-emacro(438, VRBT_*) // last value assigned ... not used
-emacro(613, VRBT_*) // Possible use of null pointer
-emacro(845, VRBT_*) // The left argument to operator '&&' is certain to be 0
-emacro(774, VRBT_*) // if (...)
-emacro(838, VRBT_*) // Previously assigned value to variable
/// queue.h
// 506 = constant value boolean
-emacro(506, V*TAILQ_FOREACH_*)
// 826 = Suspicious pointer-to-pointer conversion (area to o small)
-emacro((826), VTAILQ_LAST)
-emacro((826), VTAILQ_PREV)
-emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types)
-emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types)
// varnish-cache
-emacro(747, ALLOC_OBJ) // Significant prototype coercion
-emacro(747, WS_TASK_ALLOC_OBJ) // Significant prototype coercion
-ecall(747, WS_Alloc) // Significant prototype coercion
// vmodtool
-esym(763, vmod_*)
// VRT crossing
-esym(526, VSUB_*, VFIL_*)
\ No newline at end of file
......@@ -44,15 +44,12 @@
#include "cache/cache.h"
#include "cache/cache_filter.h"
#include "vcl.h"
#include "vtree.h"
#include "from_varnish/vfil.h"
#include "from_varnish/vsub.h"
#include "vcc_if.h"
extern char **environ;
#define VFAIL(ctx, type, fmt, ...) \
VRT_fail((ctx), type " pipe failure: " fmt, __VA_ARGS__)
......@@ -71,7 +68,7 @@ struct setenv_entry {
VSTAILQ_ENTRY(setenv_entry) list;
char *var;
char *value;
VCL_BOOL overwrite;
int overwrite;
};
VSTAILQ_HEAD(setenv_head, setenv_entry);
......@@ -84,7 +81,7 @@ struct VPFX(pipe_vdp) {
struct vdp *vdp;
char **argv;
struct setenv_head *setenv_head;
ssize_t bufsz;
size_t bufsz;
int argc;
int tmo_ms;
};
......@@ -114,8 +111,16 @@ map_cmp(const struct vdp_map *v1, const struct vdp_map *v2)
VRBT_HEAD(vdp_tree, vdp_map);
VRBT_PROTOTYPE_STATIC(vdp_tree, vdp_map, entry, map_cmp);
VRBT_GENERATE_STATIC(vdp_tree, vdp_map, entry, map_cmp);
VRBT_GENERATE_INSERT_COLOR(vdp_tree, vdp_map, entry, static)
VRBT_GENERATE_FIND(vdp_tree, vdp_map, entry, map_cmp, static)
#ifdef VRBT_GENERATE_INSERT_FINISH
VRBT_GENERATE_INSERT_FINISH(vdp_tree, vdp_map, entry, static)
#endif
VRBT_GENERATE_INSERT(vdp_tree, vdp_map, entry, map_cmp, static)
VRBT_GENERATE_REMOVE_COLOR(vdp_tree, vdp_map, entry, static)
VRBT_GENERATE_REMOVE(vdp_tree, vdp_map, entry, static)
VRBT_GENERATE_NEXT(vdp_tree, vdp_map, entry, static)
VRBT_GENERATE_MINMAX(vdp_tree, vdp_map, entry, static)
static struct vdp_tree tree_h;
......@@ -128,7 +133,7 @@ struct vdp_state {
pid_t chldpid;
};
static const char *stream_name[] = {
static const char * const stream_name[] = {
[STDIN_FILENO] = "stdin",
[STDOUT_FILENO] = "stdout",
[STDERR_FILENO] = "stderr",
......@@ -395,7 +400,7 @@ vdp_bytes(struct vdp_ctx *ctx, enum vdp_action act, void **priv,
closefd(&fds[STDIN_FILENO].fd);
errno = 0;
retval = poll(fds, 3, obj->tmo_ms);
retval = poll(fds, (nfds_t)3, obj->tmo_ms);
if (retval < 0) {
assert(errno == EINTR);
continue;
......@@ -429,7 +434,8 @@ vdp_bytes(struct vdp_ctx *ctx, enum vdp_action act, void **priv,
continue;
errno = 0;
nbytes = write(fds[STDIN_FILENO].fd, ptr, len);
nbytes = write(fds[STDIN_FILENO].fd,
ptr, (size_t)len);
if (nbytes < 0) {
VSLb(ctx->vsl, SLT_Error,
"vdfp_pipe: vdp %s: error writing "
......@@ -453,7 +459,8 @@ vdp_bytes(struct vdp_ctx *ctx, enum vdp_action act, void **priv,
}
closefd(&fds[STDOUT_FILENO].fd);
if (act_bytes != VDP_END)
VDP_bytes(ctx, VDP_END, NULL, 0);
(void) VDP_bytes(ctx, VDP_END,
NULL, (size_t)0);
continue;
}
errno = 0;
......@@ -470,7 +477,7 @@ vdp_bytes(struct vdp_ctx *ctx, enum vdp_action act, void **priv,
assert(nbytes > 0);
if (i == STDOUT_FILENO &&
fds[i].revents & POLLHUP &&
nbytes < obj->bufsz) {
(size_t)nbytes < obj->bufsz) {
act_bytes = VDP_END;
}
if (i == STDOUT_FILENO) {
......@@ -486,11 +493,12 @@ vdp_bytes(struct vdp_ctx *ctx, enum vdp_action act, void **priv,
/* Log the stderr message one line at a time. */
for (char *errmsg = state->buf; nbytes > 0;) {
size_t linelen;
char *newline = memchr(errmsg, '\n', nbytes);
char *newline =
memchr(errmsg, '\n', (size_t)nbytes);
if (newline == NULL)
linelen = nbytes;
linelen = (size_t)nbytes;
else
linelen = newline - errmsg;
linelen = (size_t)(newline - errmsg);
assert(linelen <= (unsigned)nbytes);
if (linelen == 0) {
nbytes--;
......@@ -501,8 +509,9 @@ vdp_bytes(struct vdp_ctx *ctx, enum vdp_action act, void **priv,
"vdfp_pipe: vdp %s: %s stderr: %.*s",
obj->name, obj->path, (int)linelen,
errmsg);
nbytes -= (linelen + 1);
errmsg += (linelen + 1);
linelen++;
nbytes -= (ssize_t)linelen;
errmsg += linelen;
}
}
if (act == VDP_END && fds[STDOUT_FILENO].fd != -1)
......@@ -566,7 +575,7 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
}
map = VRBT_NEXT(vdp_tree, &tree_h, map);
if (prev_map != NULL) {
VRBT_REMOVE(vdp_tree, &tree_h, prev_map);
AN(VRBT_REMOVE(vdp_tree, &tree_h, prev_map));
FREE_OBJ(prev_map);
}
}
......@@ -640,7 +649,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
CHK_NAME("V1B");
CHK_NAME("H2B");
if (bufsz == 0)
if (bufsz <= 0)
bufsz = DEFAULT_BUFSZ;
errno = 0;
......@@ -652,8 +661,8 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
}
vdp_obj->name = strdup(obj_name);
vdp_obj->path = strdup(path);
vdp_obj->bufsz = bufsz;
vdp_obj->tmo_ms = timeout * 1000;
vdp_obj->bufsz = (size_t)bufsz;
vdp_obj->tmo_ms = (int)(timeout * 1000);
AZ(vdp_obj->setenv_head);
errno = 0;
......@@ -704,6 +713,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
AZ(VRBT_INSERT(vdp_tree, &tree_h, map));
*vdpp = vdp_obj;
//lint -e{429} Flexelint does not grok map insert
return;
}
......@@ -788,6 +798,7 @@ VCL_VOID
vmod_vdp_arg(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING arg)
{
struct task_cfg *task;
size_t sz;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
......@@ -802,16 +813,20 @@ vmod_vdp_arg(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING arg)
if (ctx->method & VCL_MET_INIT) {
errno = 0;
obj->argv = realloc(obj->argv,
(obj->argc + 2) * sizeof(*obj->argv));
assert(obj->argc >= 0);
assert(obj->argc < INT_MAX);
sz = (unsigned)obj->argc;
sz += 2;
sz *= sizeof *obj->argv;
obj->argv = realloc(obj->argv, sz);
if (obj->argv == NULL) {
VDPFAIL(ctx, "%s.arg(): cannot re-allocate argv: %s",
obj->name, VAS_errtxt(errno));
return;
}
obj->argv[obj->argc] = strdup(arg);
obj->argv[obj->argc + 1] = NULL;
obj->argc++;
obj->argv[obj->argc++] = strdup(arg);
obj->argv[obj->argc] = NULL;
return;
}
......@@ -837,21 +852,26 @@ vmod_vdp_arg(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING arg)
return;
}
assert(task->argc >= 0);
assert(task->argc < INT_MAX);
sz = (unsigned)task->argc;
sz += 2;
sz *= sizeof *task->argv;
errno = 0;
task->argv = realloc(task->argv,
(task->argc + 2) * sizeof(*task->argv));
task->argv = realloc(task->argv, sz);
if (task->argv == NULL) {
VDPFAIL(ctx, "%s.arg(): cannot re-allocate argv: %s", obj->name,
VAS_errtxt(errno));
return;
}
if ((task->argv[task->argc] = WS_Copy(ctx->ws, arg, -1)) == NULL) {
if ((task->argv[task->argc++] = WS_Copy(ctx->ws, arg, -1)) == NULL) {
VDPFAIL(ctx, "%s.arg(): insufficient workspace for %s",
obj->name, arg);
return;
}
task->argv[task->argc + 1] = NULL;
task->argc++;
task->argv[task->argc] = NULL;
return;
}
......@@ -907,7 +927,7 @@ vmod_vdp_setenv(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING var,
entry->var = strdup(var);
entry->value = strdup(value);
entry->overwrite = overwrite;
entry->overwrite = overwrite ? 1 : 0;
VSTAILQ_INSERT_TAIL(obj->setenv_head, entry, list);
return;
}
......@@ -942,7 +962,7 @@ vmod_vdp_setenv(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING var,
obj->name);
return;
}
entry->overwrite = overwrite;
entry->overwrite = overwrite ? 1 : 0;
VSTAILQ_INSERT_TAIL(task->setenv_head, entry, list);
}
......
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