[master] a04d4d7 try to make flexelint a bit happier

Nils Goroll nils.goroll at uplex.de
Mon Sep 12 22:07:12 CEST 2016


commit a04d4d7f53c4f58ff4dc3df39a0b319c8a3e26bf
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 12 21:22:47 2016 +0200

    try to make flexelint a bit happier

diff --git a/lib/libvmod_directors/crc32.c b/lib/libvmod_directors/crc32.c
index 714b0f0..94b2405 100644
--- a/lib/libvmod_directors/crc32.c
+++ b/lib/libvmod_directors/crc32.c
@@ -104,9 +104,12 @@ crc32_l(const void *p1, unsigned l)
 #ifdef DEBUG
 
 #include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
 int main(int argc, char *argv[]) {
 	if (argc > 1)
 		printf("%x\n", crc32_l(argv[1], strlen(argv[1])));
+	return 0;
 }
 
 #endif
diff --git a/lib/libvmod_directors/shard_cfg.c b/lib/libvmod_directors/shard_cfg.c
index ecfb936..44e5c28 100644
--- a/lib/libvmod_directors/shard_cfg.c
+++ b/lib/libvmod_directors/shard_cfg.c
@@ -148,7 +148,7 @@ shard_change_task_add(VRT_CTX, struct shard_change *change,
 
 static inline VCL_BOOL
 shard_change_task_backend(VRT_CTX,
-    struct vmod_priv *priv, struct sharddir *shardd,
+    struct vmod_priv *priv, const struct sharddir *shardd,
     enum shard_change_task_e task_e, VCL_BACKEND be, VCL_STRING ident,
     VCL_DURATION rampup)
 {
@@ -183,8 +183,9 @@ shard_change_task_backend(VRT_CTX,
  * director reconfiguration tasks
  */
 VCL_BOOL
-shardcfg_add_backend(VRT_CTX, struct vmod_priv *priv, struct sharddir *shardd,
-    VCL_BACKEND be, VCL_STRING ident, VCL_DURATION rampup)
+shardcfg_add_backend(VRT_CTX, struct vmod_priv *priv,
+    const struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident,
+    VCL_DURATION rampup)
 {
 	AN(be);
 	return shard_change_task_backend(ctx, priv, shardd, ADD_BE,
@@ -193,14 +194,14 @@ shardcfg_add_backend(VRT_CTX, struct vmod_priv *priv, struct sharddir *shardd,
 
 VCL_BOOL
 shardcfg_remove_backend(VRT_CTX, struct vmod_priv *priv,
-    struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident)
+    const struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident)
 {
 	return shard_change_task_backend(ctx, priv, shardd, REMOVE_BE,
 	    be, ident, 0);
 }
 
 VCL_BOOL
-shardcfg_clear(VRT_CTX, struct vmod_priv *priv, struct sharddir *shardd)
+shardcfg_clear(VRT_CTX, struct vmod_priv *priv, const struct sharddir *shardd)
 {
 	struct shard_change *change;
 
@@ -223,7 +224,8 @@ shardcfg_clear(VRT_CTX, struct vmod_priv *priv, struct sharddir *shardd)
 typedef int (*compar)( const void*, const void* );
 
 static int
-circlepoint_compare(struct shard_circlepoint *a, struct shard_circlepoint *b)
+circlepoint_compare(const struct shard_circlepoint *a,
+    const struct shard_circlepoint *b)
 {
 	return (a->point == b->point) ? 0 : ((a->point > b->point) ? 1 : -1);
 }
@@ -256,7 +258,7 @@ shardcfg_hashcircle(struct sharddir *shardd, VCL_INT replicas, enum alg_e alg)
 
 		assert(ident[0] != '\0');
 
-		len = strlen(ident) + log10(UINT32_MAX) + 2;
+		len = strlen(ident) + 12; // log10(UINT32_MAX) + 2;
 
 		char s[len];
 
@@ -280,7 +282,7 @@ shardcfg_hashcircle(struct sharddir *shardd, VCL_INT replicas, enum alg_e alg)
 		for (j = 0; j < replicas; j++)
 			SHDBG(SHDBG_CIRCLE, shardd,
 			    "hashcircle[%5ld] = "
-			    "{point = %8x, host = %2d}\n",
+			    "{point = %8x, host = %2u}\n",
 			    i * replicas + j,
 			    shardd->hashcircle[i * replicas + j].point,
 			    shardd->hashcircle[i * replicas + j].host);
@@ -343,7 +345,7 @@ shardcfg_backend_del_cmp(const struct shard_backend *task,
 }
 
 static const struct shard_backend *
-shardcfg_backend_lookup(struct backend_reconfig *re,
+shardcfg_backend_lookup(const struct backend_reconfig *re,
     const struct shard_backend *b)
 {
 	int i, max = re->shardd->n_backend + re->hole_n;
@@ -357,7 +359,7 @@ shardcfg_backend_lookup(struct backend_reconfig *re,
 }
 
 static void
-shardcfg_backend_expand(struct backend_reconfig *re)
+shardcfg_backend_expand(const struct backend_reconfig *re)
 {
 	int min = re->hint;
 
@@ -612,7 +614,7 @@ shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv,
 
 /* only for sharddir_delete() */
 void
-shardcfg_delete(struct sharddir *shardd)
+shardcfg_delete(const struct sharddir *shardd)
 {
 	int i;
 
@@ -645,7 +647,7 @@ shardcfg_set_rampup(struct sharddir *shardd, VCL_DURATION duration)
 }
 
 VCL_DURATION
-shardcfg_get_rampup(struct sharddir *shardd, int host)
+shardcfg_get_rampup(const struct sharddir *shardd, int host)
 {
 	VCL_DURATION r;
 
diff --git a/lib/libvmod_directors/shard_cfg.h b/lib/libvmod_directors/shard_cfg.h
index ca50ddd..8d1d88c 100644
--- a/lib/libvmod_directors/shard_cfg.h
+++ b/lib/libvmod_directors/shard_cfg.h
@@ -27,12 +27,12 @@
  */
 
 VCL_BOOL shardcfg_add_backend(VRT_CTX, struct vmod_priv *priv,
-    struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident,
+    const struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident,
     VCL_DURATION rampup);
 VCL_BOOL shardcfg_remove_backend(VRT_CTX, struct vmod_priv *priv,
-    struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident);
+    const struct sharddir *shardd, VCL_BACKEND be, VCL_STRING ident);
 VCL_BOOL shardcfg_clear(VRT_CTX, struct vmod_priv *priv,
-    struct sharddir *shardd);
+    const struct sharddir *shardd);
 VCL_BOOL shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv,
     struct sharddir *shardd, VCL_INT replicas, enum alg_e alg_e);
 VCL_VOID shardcfg_set_warmup(struct sharddir *shardd, VCL_REAL ratio);
diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c
index 57a9495..54202f8 100644
--- a/lib/libvmod_directors/shard_dir.c
+++ b/lib/libvmod_directors/shard_dir.c
@@ -44,7 +44,6 @@
 #include "vrnd.h"
 
 #include "shard_dir.h"
-#include "shard_hash.h"
 
 struct shard_be_info {
 	int		hostid;
@@ -98,7 +97,7 @@ shard_lookup(const struct sharddir *shardd, const uint32_t key)
 	int idx = -1, high = n, low = 0, i;
 
 	do {
-	    i = (high + low) >> 1;
+	    i = (high + low) / 2 ;
 	    if (shardd->hashcircle[i].point == key)
 		idx = i;
 	    else if (i == n - 1)
@@ -232,7 +231,7 @@ sharddir_unlock(struct sharddir *shardd)
 }
 
 static inline void
-validate_alt(VRT_CTX, struct sharddir *shardd, VCL_INT *alt)
+validate_alt(VRT_CTX, const struct sharddir *shardd, VCL_INT *alt)
 {
 	const VCL_INT alt_max = shardd->n_backend - 1;
 
@@ -257,7 +256,6 @@ init_state(struct shard_state *state,
 	state->shardd = shardd;
 	state->idx = -1;
 	state->picklist = picklist;
-	state->pickcount = 0;
 
 	/* healhy and changed only defined for hostid != -1 */
 	state->previous.hostid = -1;
@@ -311,6 +309,7 @@ sharddir_pick_be(VRT_CTX, struct sharddir *shardd,
 
 	validate_alt(ctx, shardd, &alt);
 
+	memset(&state, 0, sizeof(state));
 	init_state(&state, ctx, shardd, vbit_init(picklist_spc, picklist_sz));
 
 	state.idx = shard_lookup(shardd, key);
diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h
index b66fca1..f40d0ac 100644
--- a/lib/libvmod_directors/shard_dir.h
+++ b/lib/libvmod_directors/shard_dir.h
@@ -95,10 +95,10 @@ sharddir_backend_ident(const struct sharddir *shardd, int host)
 		    (shardd)->name, __VA_ARGS__);			\
 	} while (0)
 
-#define shard_err0(ctx, shardd, s)					\
+#define shard_err0(ctx, shardd, msg)					\
 	do {								\
 		sharddir_err(ctx, SLT_Error, "shard %s: %s",		\
-		    (shardd)->name, (s));				\
+		    (shardd)->name, (msg));				\
 	} while (0)
 
 void sharddir_debug(struct sharddir *shardd, const uint32_t flags);
@@ -113,5 +113,5 @@ VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT,
    VCL_REAL, VCL_BOOL, enum healthy_e);
 
 /* in shard_cfg.c */
-void shardcfg_delete(struct sharddir *shardd);
-VCL_DURATION shardcfg_get_rampup(struct sharddir *shardd, int host);
+void shardcfg_delete(const struct sharddir *shardd);
+VCL_DURATION shardcfg_get_rampup(const struct sharddir *shardd, int host);
diff --git a/lib/libvmod_directors/shard_hash.c b/lib/libvmod_directors/shard_hash.c
index 30ebd7d..eacc250 100644
--- a/lib/libvmod_directors/shard_hash.c
+++ b/lib/libvmod_directors/shard_hash.c
@@ -92,7 +92,7 @@ _shard_hash_invalid(VCL_STRING s)
 {
 	(void) s;
 	WRONG("invalid hash fp _ALG_E_ENVALID");
-	return (0);
+	NEEDLESS_RETURN(0);
 }
 
 hash_func shard_hash_f[_ALG_E_MAX] = {
diff --git a/lib/libvmod_directors/shard_parse_vcc_enums.c b/lib/libvmod_directors/shard_parse_vcc_enums.c
index 5dec48e..e362450 100644
--- a/lib/libvmod_directors/shard_parse_vcc_enums.c
+++ b/lib/libvmod_directors/shard_parse_vcc_enums.c
@@ -67,7 +67,7 @@ enum by_e parse_by_e (const char *m) {
 	 _0B:
 	//BLOB
 	if ((m[1] == 'L') && (m[2] == 'O') && (m[3] == 'B') && (term(m[4]))) {
-	    r = BLOB;
+	    r = BY_BLOB;
 	    p = 4;
 	    goto ok;
 	}
@@ -75,7 +75,7 @@ enum by_e parse_by_e (const char *m) {
 	 _0H:
 	//HASH
 	if ((m[1] == 'A') && (m[2] == 'S') && (m[3] == 'H') && (term(m[4]))) {
-	    r = HASH;
+	    r = BY_HASH;
 	    p = 4;
 	    goto ok;
 	}
@@ -83,7 +83,7 @@ enum by_e parse_by_e (const char *m) {
 	 _0K:
 	//KEY
 	if ((m[1] == 'E') && (m[2] == 'Y') && (term(m[3]))) {
-	    r = KEY;
+	    r = BY_KEY;
 	    p = 3;
 	    goto ok;
 	}
@@ -91,7 +91,7 @@ enum by_e parse_by_e (const char *m) {
 	 _0U:
 	//URL
 	if ((m[1] == 'R') && (m[2] == 'L') && (term(m[3]))) {
-	    r = URL;
+	    r = BY_URL;
 	    p = 3;
 	    goto ok;
 	}
diff --git a/lib/libvmod_directors/shard_parse_vcc_enums.h b/lib/libvmod_directors/shard_parse_vcc_enums.h
index aa097dc..d6e2ff9 100644
--- a/lib/libvmod_directors/shard_parse_vcc_enums.h
+++ b/lib/libvmod_directors/shard_parse_vcc_enums.h
@@ -19,10 +19,10 @@ enum alg_e parse_alg_e (const char *);
 
 enum by_e {
 	_BY_E_INVALID = 0,
-	HASH,
-	URL,
-	KEY,
-	BLOB,
+	BY_HASH,
+	BY_URL,
+	BY_KEY,
+	BY_BLOB,
 	_BY_E_MAX
 };
 
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 7acb59b..52c9710 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -184,13 +184,13 @@ get_key(VRT_CTX, enum by_e by, VCL_INT key_int, VCL_BLOB key_blob)
 	int i, ki;
 
 	switch (by) {
-	case HASH:
+	case BY_HASH:
 		if (ctx->bo) {
 			CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
 			return (vbe32dec(ctx->bo->digest));
 		}
 		/* FALLTHROUGH */
-	case URL:
+	case BY_URL:
 		if (ctx->http_req) {
 			AN(http = ctx->http_req);
 		} else {
@@ -198,11 +198,9 @@ get_key(VRT_CTX, enum by_e by, VCL_INT key_int, VCL_BLOB key_blob)
 			AN(http = ctx->http_bereq);
 		}
 		return (shard_hash_f[SHA256](http->hd[HTTP_HDR_URL].b));
-		break;
-	case KEY:
+	case BY_KEY:
 		return ((uint32_t)key_int);
-		break;
-	case BLOB:
+	case BY_BLOB:
 		assert(key_blob);
 		assert(key_blob->len > 0);
 		assert(key_blob->priv != NULL);
@@ -218,7 +216,6 @@ get_key(VRT_CTX, enum by_e by, VCL_INT key_int, VCL_BLOB key_blob)
 		assert(i <= key_blob->len);
 
 		return (vbe32dec(k));
-		break;
 	default:
 		WRONG("by value");
 	}
@@ -237,26 +234,26 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC);
 
-	if (key_int && by != KEY) {
+	if (key_int && by != BY_KEY) {
 		shard_err(ctx, vshard->shardd,
 		    "by=%s but key argument used", by_s);
 		return NULL;
 	}
 
-	if (key_blob && by != BLOB) {
+	if (key_blob && by != BY_BLOB) {
 		shard_err(ctx, vshard->shardd,
 		    "by=%s but key_blob argument used", by_s);
 		return NULL;
 	}
 
-	if (by == BLOB) {
+	if (by == BY_BLOB) {
 		if (key_blob == NULL ||
 		    key_blob->len <= 0 ||
 		    key_blob->priv == NULL) {
 			shard_err0(ctx, vshard->shardd,
 			    "by=BLOB but no or empty key_blob "
 			    "- using key 0");
-			by = KEY;
+			by = BY_KEY;
 			key_int = 0;
 		}
 	}



More information about the varnish-commit mailing list