Stricter flexelinting

parent 88d42892
......@@ -26,6 +26,8 @@
-esym(844, vmod_priv_blob*, VGC_*)
-esym(768, arg_vmod_blob*)
-emacro(774, REPLACE) // 'if' always evaluates to False
-emacro(747, ALLOC_OBJ)
-efunc(663, tus_obj*, tus_body_assign) // suspicious array oc->stobj
// not fully understood
-efunc(413, *_VSPLAY_NEXT)
......
This diff is collapsed.
......@@ -185,7 +185,7 @@ tus_file_exp_new(void)
AZ(pthread_cond_init(&e->cond, NULL));
AZ(pthread_attr_init(&attr));
AZ(pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN));
AZ(pthread_attr_setstacksize(&attr, (size_t)PTHREAD_STACK_MIN));
AZ(pthread_create(&e->thread, &attr, tus_exp_thread, e));
AZ(pthread_attr_destroy(&attr));
return (e);
......
......@@ -28,6 +28,8 @@
#include "config.h"
#include <limits.h>
#include "cache/cache.h"
#include "vsb.h"
......@@ -38,7 +40,11 @@
static inline char
hexnibble(unsigned char n)
{
return (n < 0xa ? '0' + n : 'a' + n - 0xa);
unsigned char c;
assert(n <= 0xf);
c = n < 0xa ? '0' + n : 'a' + (n - 0xa);
assert(c <= 'f');
return ((char)c);
}
static VCL_STRING
......@@ -83,7 +89,8 @@ tus_hex(VRT_CTX, VCL_BLOB b)
return ("");
bufl = b->len * 2 + 1;
buf = WS_Alloc(ctx->ws, bufl);
assert(bufl <= UINT_MAX);
buf = WS_Alloc(ctx->ws, (unsigned)bufl);
if (buf == NULL)
return (NULL);
......@@ -95,5 +102,5 @@ tus_vsbhex(struct vsb *vsb, VCL_BLOB b)
{
size_t l = b->len * 2 + 1;
char buf[l];
VSB_cat(vsb, tus_hex_buf(buf, l, b));
AZ(VSB_cat(vsb, tus_hex_buf(buf, l, b)));
}
......@@ -35,10 +35,7 @@
#include <cache/cache.h>
#include <vsb.h>
#include "vcc_tus_if.h"
#include "tus_file.h"
#include "tus_servers.h"
#include "tus_hdr.h"
#include "tus_response.h"
#include "tus_request.h"
......@@ -97,7 +94,8 @@ tus_request_complete(VRT_CTX, const struct VPFX(tus_server) *srv,
p = strrchr(fdisk->upload_path, '/');
AN(p);
WS_VSB_new(vsb, ctx->ws);
VSB_bcat(vsb, fdisk->upload_path, (p - fdisk->upload_path) + 1);
(void)VSB_bcat(vsb, fdisk->upload_path,
(p - fdisk->upload_path) + 1);
tus_vsbhex(vsb, b);
http_SetH(ctx->http_req, HTTP_HDR_URL,
WS_VSB_finish(vsb, ctx->ws, NULL));
......@@ -112,8 +110,8 @@ tus_request_complete(VRT_CTX, const struct VPFX(tus_server) *srv,
http_Unset(ctx->http_req, H_Content_Type);
if (tus_file_meta(ctx, fdisk, "filetype", &b)) {
WS_VSB_new(vsb, ctx->ws);
VSB_bcat(vsb, b->blob, b->len);
VSB_putc(vsb, '\0');
(void)VSB_bcat(vsb, b->blob, (ssize_t)b->len);
(void)VSB_putc(vsb, '\0');
p = WS_VSB_finish(vsb, ctx->ws, NULL);
if (validhdr(p))
http_ForceHeader(ctx->http_req, H_Content_Type, p);
......@@ -203,6 +201,7 @@ static VCL_BOOL
tus_metadata_validate(const char *s, struct test_meta *prev)
{
struct test_meta this = {prev, s, 0};
size_t sz;
// key
while (1) {
......@@ -211,7 +210,9 @@ tus_metadata_validate(const char *s, struct test_meta *prev)
continue;
}
if (tus_meta_key_unique(&this, s - this.k) == 0)
assert(s >= this.k);
sz = (size_t)(s - this.k);
if (tus_meta_key_unique(&this, sz) == 0)
return (0);
if (*s == '\0')
......@@ -323,8 +324,10 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
r->fcore = tus_file_lookup(tussrv, url);
}
if (r->fcore != NULL)
r->schemeauth = WS_Copy(ctx->ws, tussrv->schemeauth, -1);
if (r->fcore != NULL) {
r->schemeauth = WS_Copy(ctx->ws,
tus_server_schemeauth(tussrv), -1);
}
lock = tus_file_trylock(&r->fcore);
tus_server_unlock(tussrv);
......@@ -437,8 +440,8 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if (len != UINTMAX_MAX) {
if (fdisk->upload_length == -1)
fdisk->upload_length = len;
else if (len != fdisk->upload_length) {
fdisk->upload_length = (ssize_t)len;
else if ((ssize_t)len != fdisk->upload_length) {
r->s.status = 409; // or 400 ?
return (0);
}
......@@ -456,13 +459,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
assert (type != TUS_FINAL);
/*lint -e{788} enums not used */
switch (m) {
case PATCH: {
if (! ct_ok) {
r->s.status = 415;
return (0);
}
if (off != fdisk->upload_offset) {
if ((ssize_t)off != fdisk->upload_offset) {
r->s.status = 409;
return (0);
}
......
......@@ -44,14 +44,20 @@ const unsigned s_OPTIONS = 1;
static const char * const allow = "POST, GET, HEAD, PATCH, DELETE, OPTIONS";
// vmod/vmod_std_conversions.c
#define VCL_BYTES_MAX ((INT64_C(1)<<53)-1)
static VCL_BYTES
tus_upload_length(const struct VPFX(tus_server) *tussrv,
const struct tus_file_core *fcore)
{
VCL_BYTES srvmax, max;
VCL_BYTES srvmax;
struct statvfs fs;
size_t spc;
srvmax = tus_server_max(tussrv);
assert(srvmax >= 0);
assert(srvmax <= VCL_BYTES_MAX);
if (fcore != NULL && fcore->fd >= 0) {
if (fstatvfs(fcore->fd, &fs))
......@@ -59,8 +65,10 @@ tus_upload_length(const struct VPFX(tus_server) *tussrv,
} else if (statvfs(tus_server_basedir(tussrv), &fs))
return (srvmax);
max = fs.f_bavail * fs.f_frsize;
return (max < srvmax ? max : srvmax);
spc = fs.f_bavail * fs.f_frsize;
if (spc < (size_t)srvmax)
return ((VCL_BYTES)spc);
return (srvmax);
}
static void
......@@ -130,11 +138,10 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
loc);
}
if (resp->s.status == 301) {
VRT_l_resp_status(ctx, resp->s.status);
VRT_l_resp_status(ctx, (VCL_INT)resp->s.status);
if (resp->s.status == 301)
return;
}
VRT_l_resp_status(ctx, resp->s.status);
if (resp->s.reason != NULL) {
VRT_l_resp_reason(ctx, resp->s.reason, vrt_null_strands);
// FCK H2 - stupid idea to eliminate the reason
......@@ -199,6 +206,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
case TUS_PARTIAL:
http_ForceHeader(r, hdr_concat, "partial");
break;
case _TUS_TYPE_LIMIT:
default:
INCOMPL();
}
......
......@@ -52,3 +52,4 @@ VCL_BYTES tus_server_multipart(const struct VPFX(tus_server) *s);
struct vmod_blobdigest_digest * tus_server_digest(
const struct VPFX(tus_server) *s);
struct tus_exp *tus_server_exp(const struct VPFX(tus_server) *);
const char * tus_server_schemeauth(const struct VPFX(tus_server) *s);
......@@ -30,8 +30,6 @@
#include <cache/cache.h>
#include "vcc_tus_if.h"
#include "tus_file.h"
#include "tus_servers.h"
......@@ -136,3 +134,10 @@ tus_server_exp(const struct VPFX(tus_server) *s)
CHECK_OBJ_NOTNULL(s, VMOD_TUS_SERVER_MAGIC);
return (s->exp);
}
const char *
tus_server_schemeauth(const struct VPFX(tus_server) *s)
{
CHECK_OBJ_NOTNULL(s, VMOD_TUS_SERVER_MAGIC);
return (s->schemeauth);
}
......@@ -31,9 +31,6 @@
#include <vtree.h>
struct vmod_blobdigest_digest;
struct tus_exp;
/* ============================================================
* global server splay tree
*/
......
......@@ -80,12 +80,19 @@ tus_objsetattr(struct worker *wrk, struct objcore *oc,
enum obj_attr attr, ssize_t len, const void *ptr);
static const struct obj_methods obj_tus = {
.objfree = tus_objfree,
.objiterator = tus_objiterator,
.objgetspace = tus_objgetspace,
.objextend = tus_objextend,
.objgetattr = tus_objgetattr,
.objsetattr = tus_objsetattr
/* required */
.objfree = tus_objfree,
.objiterator = tus_objiterator,
.objgetspace = tus_objgetspace,
.objextend = tus_objextend,
.objgetattr = tus_objgetattr,
.objsetattr = tus_objsetattr,
/* optional */
.objtrimstore = NULL,
.objbocdone = NULL,
.objslim = NULL,
.objtouch = NULL,
.objsetstate = NULL
};
// ------------------------------------------------------------
......@@ -98,6 +105,7 @@ tus_allocobj(struct worker *wrk, const struct stevedore *stv,
(void) oc;
(void) l;
INCOMPL();
return (0);
}
static const struct stevedore stv_tus = {
......@@ -198,6 +206,7 @@ tus_objiterator(struct worker *wrk, struct objcore *oc,
len = fcore->len - off;
if (len > max_write)
len = max_write;
assert(len <= SSIZE_MAX);
p = (char *)fcore->ptr + off;
off += len;
......@@ -205,7 +214,7 @@ tus_objiterator(struct worker *wrk, struct objcore *oc,
if (off == fcore->len && i == c->n)
flags |= OBJ_ITER_END;
r = func(priv, flags, p, len);
r = func(priv, flags, p, (ssize_t)len);
if (r < 0)
return (r);
......@@ -215,7 +224,7 @@ tus_objiterator(struct worker *wrk, struct objcore *oc,
} while (off < fcore->len);
}
if (r == 0 && (flags & OBJ_ITER_END) == 0)
r = func(priv, flags | OBJ_ITER_END, NULL, 0);
r = func(priv, flags | OBJ_ITER_END, NULL, (ssize_t)0);
return (r);
}
......@@ -228,6 +237,7 @@ tus_objgetspace(struct worker *wrk, struct objcore *oc,
(void) sz;
(void) ptr;
INCOMPL();
return (0);
}
static void
......@@ -256,6 +266,7 @@ tus_objgetattr(struct worker *wrk, struct objcore *oc,
CAST_OBJ_NOTNULL(c, oc->stobj->priv, TUS_CONCAT_MAGIC);
/*lint -e{788} enums not used */
switch (attr) {
case OA_LEN:
l = 0;
......@@ -270,6 +281,7 @@ tus_objgetattr(struct worker *wrk, struct objcore *oc,
default:
INCOMPL();
}
return (NULL);
}
static void *
......@@ -282,6 +294,7 @@ enum obj_attr attr, ssize_t len, const void *ptr)
(void) len;
(void) ptr;
INCOMPL();
return (NULL);
}
// helper
......@@ -291,7 +304,7 @@ tus_body_single(struct req *req, struct tus_file_core *fcore)
{
struct tus_concat *c;
c = WS_Alloc(req->ws, sizeof *c + sizeof fcore);
c = WS_Alloc(req->ws, (unsigned)(sizeof *c + sizeof fcore));
if (c == NULL)
return (NULL);
INIT_OBJ(c, TUS_CONCAT_MAGIC);
......
......@@ -49,13 +49,14 @@ const struct vrt_blob *vrt_null_blob = &(struct vrt_blob){
};
int
main(int argc, char **argv) {
main(int argc, char * const *argv) {
void *dlhdl;
char buf[256], vcl[64];
const struct vmod_data *d;
const char *name;
const char *file;
int i, fd;
ssize_t ssz;
if (argc < 3) {
fprintf(stderr, "need 2 arguments\n");
......@@ -71,8 +72,8 @@ main(int argc, char **argv) {
bprintf(vcl, "/tmp/vmod_get_h_%s_XXXXXX", name);
fd = mkstemp(vcl);
assert(fd >= 0);
i = write(fd, buf, strlen(buf));
assert(i > 0);
ssz = write(fd, buf, strlen(buf));
assert(ssz > 0);
i = close(fd);
assert(i == 0);
......
......@@ -39,6 +39,7 @@
#include <vcl.h>
#include <vrt_obj.h>
//lint -esym(763, tus_tus_server)
#include "vcc_tus_if.h"
#include "tus_file.h"
......@@ -101,9 +102,10 @@ tus_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
case VCL_EVENT_DISCARD: return (tus_fini(ctx, priv));
case VCL_EVENT_WARM:
case VCL_EVENT_COLD:
return (0);
break;
default: INCOMPL();
}
return (0);
}
/* ============================================================
......@@ -160,14 +162,14 @@ static int
tus_schemeauth_valid(const char *schemeauth, const char **p)
{
*p = schemeauth;
if (*p == NULL || strncmp(*p, "http", 4) != 0)
if (*p == NULL)
return (0);
if (! TOK(*p, "http"))
return (0);
*p += 4;
if (**p == 's')
(*p)++;
if (strncmp(*p, "://", 3) != 0)
if (! TOK(*p, "://"))
return (0);
*p += 3;
if (**p == '\0')
return (0);
*p = strchr(*p, '/');
......@@ -249,13 +251,13 @@ tus_server__init(VRT_CTX, struct VPFX(tus_server) **tussrvp,
const char *vcl_name, struct VARGS(server__init) *args)
{
struct vmod_blobdigest_digest *d = NULL;
struct VPFX(tus_server) *tussrv, needle[1];
struct VPFX(tus_server) *tussrv, needle;
AN(tussrvp);
AZ(*tussrvp);
if (args->valid_name_hash) {
d = tus_hash(args->name_hash, 0);
d = tus_hash(args->name_hash, (size_t)0);
if (d == NULL) {
VRT_fail(ctx, "new %s: "
"name_hash %s not supported "
......@@ -265,10 +267,10 @@ tus_server__init(VRT_CTX, struct VPFX(tus_server) **tussrvp,
}
}
INIT_OBJ(needle, VMOD_TUS_SERVER_MAGIC);
needle->vcl_name = TRUST_ME(vcl_name);
INIT_OBJ(&needle, VMOD_TUS_SERVER_MAGIC);
needle.vcl_name = TRUST_ME(vcl_name);
tussrv = VSPLAY_FIND(tus_servers, tus_servers, needle);
tussrv = VSPLAY_FIND(tus_servers, tus_servers, &needle);
if (tussrv == NULL)
tussrv = tus_server_new(ctx, vcl_name, args);
else
......@@ -357,7 +359,7 @@ tus_task_new(VRT_CTX, const struct VPFX(tus_server) *tussrv)
return (NULL);
}
r = WS_Alloc(ctx->ws, sizeof *r);
r = WS_Alloc(ctx->ws, (unsigned)sizeof *r);
if (r == NULL) {
VRT_fail(ctx, "WS_Alloc failed");
return (NULL);
......
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