[master] d0a8130 take more advice from flexelint

Nils Goroll nils.goroll at uplex.de
Tue Sep 13 00:02:12 CEST 2016


commit d0a81307fdeaef96625ff4cadc4b0cbc854e2252
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 12 22:53:16 2016 +0200

    take more advice from flexelint

diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c
index 54202f8..91f70d3 100644
--- a/lib/libvmod_directors/shard_dir.c
+++ b/lib/libvmod_directors/shard_dir.c
@@ -299,6 +299,9 @@ sharddir_pick_be(VRT_CTX, struct sharddir *shardd,
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(ctx->vsl);
 
+	memset(&state, 0, sizeof(state));
+	init_state(&state, ctx, shardd, vbit_init(picklist_spc, picklist_sz));
+
 	sharddir_rdlock(shardd);
 	if(shardd->n_backend == 0) {
 		shard_err0(ctx, shardd, "no backends");
@@ -309,17 +312,14 @@ 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);
 	assert(state.idx >= 0);
 
-	SHDBG(SHDBG_LOOKUP, shardd, "lookup key %x idx %d host %d",
+	SHDBG(SHDBG_LOOKUP, shardd, "lookup key %x idx %d host %u",
 	    key, state.idx, shardd->hashcircle[state.idx].host);
 
 	if (alt > 0) {
-		if (shard_next(&state, alt - 1, healthy == ALL) == -1) {
+		if (shard_next(&state, alt - 1, healthy == ALL ? 1 : 0) == -1) {
 			if (state.previous.hostid != -1) {
 				be = sharddir_backend(shardd,
 				    state.previous.hostid);
@@ -329,7 +329,7 @@ sharddir_pick_be(VRT_CTX, struct sharddir *shardd,
 		}
 	}
 
-	if (shard_next(&state, 0, healthy != IGNORE) == -1) {
+	if (shard_next(&state, 0, healthy == IGNORE ? 0 : 1) == -1) {
 		if (state.previous.hostid != -1) {
 			be = sharddir_backend(shardd, state.previous.hostid);
 			goto ok;
diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h
index f40d0ac..de35c41 100644
--- a/lib/libvmod_directors/shard_dir.h
+++ b/lib/libvmod_directors/shard_dir.h
@@ -105,7 +105,6 @@ void sharddir_debug(struct sharddir *shardd, const uint32_t flags);
 void sharddir_err(VRT_CTX, enum VSL_tag_e tag,  const char *fmt, ...);
 void sharddir_new(struct sharddir **sharddp, const char *vcl_name);
 void sharddir_delete(struct sharddir **sharddp);
-void sharddir_init_hashcircle(struct sharddir *shardd, VCL_INT replicas);
 void sharddir_rdlock(struct sharddir *shardd);
 void sharddir_wrlock(struct sharddir *shardd);
 void sharddir_unlock(struct sharddir *shardd);
diff --git a/lib/libvmod_directors/shard_hash.c b/lib/libvmod_directors/shard_hash.c
index 63317bf..aa66410 100644
--- a/lib/libvmod_directors/shard_hash.c
+++ b/lib/libvmod_directors/shard_hash.c
@@ -47,13 +47,13 @@
  * dependency nightmare (at least for now)
  */
 
-unsigned long crc32(unsigned long, const void *buf, unsigned len);
+unsigned long crc32(unsigned long, const unsigned char *buf, unsigned len);
 
 static uint32_t __match_proto__(hash_func)
 shard_hash_crc32(VCL_STRING s)
 {
 	uint32_t crc;
-	crc = crc32(~0U, s, strlen(s));
+	crc = crc32(~0U, (const unsigned char *)s, strlen(s));
 	crc ^= ~0U;
 	return (crc);
 }
@@ -104,7 +104,7 @@ _shard_hash_invalid(VCL_STRING s)
 	NEEDLESS_RETURN(0);
 }
 
-hash_func shard_hash_f[_ALG_E_MAX] = {
+const hash_func shard_hash_f[_ALG_E_MAX] = {
 	[_ALG_E_INVALID] = _shard_hash_invalid,
 	[CRC32]	 = shard_hash_crc32,
 	[SHA256]	 = shard_hash_sha256,
diff --git a/lib/libvmod_directors/shard_hash.h b/lib/libvmod_directors/shard_hash.h
index 5ee38ad..838032a 100644
--- a/lib/libvmod_directors/shard_hash.h
+++ b/lib/libvmod_directors/shard_hash.h
@@ -27,4 +27,4 @@
  */
 
 typedef uint32_t (*hash_func)(VCL_STRING);
-extern hash_func shard_hash_f[_ALG_E_MAX];
+extern const hash_func shard_hash_f[_ALG_E_MAX];



More information about the varnish-commit mailing list