From 68a4588a6fb4c77c6dd34f5d98643525e169c32c Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 21 Jun 2019 14:37:11 +1000 Subject: [PATCH] ctdb-tests: Fix signed/unsigned comparisons by declaring as unsigned Change declarations of variable and parameters, usually loop variables and limits, from int to unsigned int, size_t or uint32_t. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/tests/src/cluster_wait.c | 6 ++-- ctdb/tests/src/cluster_wait.h | 2 +- ctdb/tests/src/comm_client_test.c | 7 ++-- ctdb/tests/src/comm_test.c | 6 ++-- ctdb/tests/src/ctdb_packet_parse.c | 2 +- ctdb/tests/src/errcode.c | 6 ++-- ctdb/tests/src/event_script_test.c | 3 +- ctdb/tests/src/fake_ctdbd.c | 19 +++++------ ctdb/tests/src/fetch_ring.c | 6 ++-- ctdb/tests/src/protocol_basic_test.c | 3 +- ctdb/tests/src/protocol_common.c | 36 ++++++++++----------- ctdb/tests/src/protocol_common_basic.c | 4 +-- ctdb/tests/src/protocol_ctdb_compat_test.c | 2 +- ctdb/tests/src/protocol_ctdb_test.c | 2 +- ctdb/tests/src/protocol_types_compat_test.c | 28 ++++++++-------- ctdb/tests/src/run_event_test.c | 6 ++-- ctdb/tests/src/sigcode.c | 6 ++-- 17 files changed, 76 insertions(+), 68 deletions(-) diff --git a/ctdb/tests/src/cluster_wait.c b/ctdb/tests/src/cluster_wait.c index 8b0bb429e81..d411591765b 100644 --- a/ctdb/tests/src/cluster_wait.c +++ b/ctdb/tests/src/cluster_wait.c @@ -34,7 +34,7 @@ struct cluster_wait_state { struct tevent_context *ev; struct ctdb_client_context *client; - int num_nodes; + uint32_t num_nodes; bool *ready; bool join_done; }; @@ -54,7 +54,7 @@ static void cluster_wait_sync_unregistered(struct tevent_req *subreq); struct tevent_req *cluster_wait_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct ctdb_client_context *client, - int num_nodes) + uint32_t num_nodes) { struct tevent_req *req, *subreq; struct cluster_wait_state *state; @@ -213,7 +213,7 @@ static void cluster_wait_join_handler(uint64_t srvid, TDB_DATA data, req, struct cluster_wait_state); struct tevent_req *subreq; uint32_t pnn; - int i; + uint32_t i; if (srvid != MSG_ID_JOIN) { return; diff --git a/ctdb/tests/src/cluster_wait.h b/ctdb/tests/src/cluster_wait.h index 20aa6e969ac..e0c64ccbfc6 100644 --- a/ctdb/tests/src/cluster_wait.h +++ b/ctdb/tests/src/cluster_wait.h @@ -23,7 +23,7 @@ struct tevent_req *cluster_wait_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct ctdb_client_context *client, - int num_nodes); + uint32_t num_nodes); bool cluster_wait_recv(struct tevent_req *req, int *perr); diff --git a/ctdb/tests/src/comm_client_test.c b/ctdb/tests/src/comm_client_test.c index 8db219e6ee4..41ed5f7ad46 100644 --- a/ctdb/tests/src/comm_client_test.c +++ b/ctdb/tests/src/comm_client_test.c @@ -32,7 +32,7 @@ struct writer_state { struct comm_context *comm; uint8_t *buf; size_t *pkt_size; - int count, id; + size_t count, id; }; static void writer_done(struct tevent_req *subreq); @@ -42,12 +42,13 @@ static void dead_handler(void *private_data); static struct tevent_req *writer_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, size_t *pkt_size, - int count) + size_t count) { struct tevent_req *req, *subreq; struct writer_state *state; size_t max_size = 0, buflen; - int i, ret; + size_t i; + int ret; for (i=0; i max_size) { diff --git a/ctdb/tests/src/comm_test.c b/ctdb/tests/src/comm_test.c index 5e1d6945da1..4595928e919 100644 --- a/ctdb/tests/src/comm_test.c +++ b/ctdb/tests/src/comm_test.c @@ -265,12 +265,12 @@ static void test3_writer_next(struct tevent_req *subreq); static struct tevent_req *test3_writer_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct comm_context *comm, - size_t *pkt_size, int count) + size_t *pkt_size, size_t count) { struct tevent_req *req, *subreq; struct test3_writer_state *state; size_t max_size = 0, buflen; - int i; + size_t i; for (i=0; i max_size) { @@ -352,7 +352,7 @@ static void test3_writer_recv(struct tevent_req *req, int *perr) *perr = 0; } -static void test3_writer(int fd, size_t *pkt_size, int count) +static void test3_writer(int fd, size_t *pkt_size, size_t count) { TALLOC_CTX *mem_ctx; struct tevent_context *ev; diff --git a/ctdb/tests/src/ctdb_packet_parse.c b/ctdb/tests/src/ctdb_packet_parse.c index 707d697d931..0b99b34b3ca 100644 --- a/ctdb/tests/src/ctdb_packet_parse.c +++ b/ctdb/tests/src/ctdb_packet_parse.c @@ -30,7 +30,7 @@ static TDB_DATA strace_parser(char *buf, TALLOC_CTX *mem_ctx) { TDB_DATA data; - int i = 0, j = 0; + size_t i = 0, j = 0; data.dptr = talloc_size(mem_ctx, strlen(buf)); if (data.dptr == NULL) { diff --git a/ctdb/tests/src/errcode.c b/ctdb/tests/src/errcode.c index 90853624add..7343e818be2 100644 --- a/ctdb/tests/src/errcode.c +++ b/ctdb/tests/src/errcode.c @@ -127,7 +127,7 @@ struct { static void dump(void) { - int i; + size_t i; for (i=0; inode_map->num_nodes == 0) { return true; @@ -1370,7 +1370,7 @@ static int recover_check(struct tevent_req *req) struct ctdbd_context *ctdb = state->ctdb; struct tevent_req *subreq; bool recovery_disabled; - int i; + unsigned int i; recovery_disabled = false; for (i=0; inode_map->num_nodes; i++) { @@ -1833,7 +1833,7 @@ static void control_get_dbmap(TALLOC_CTX *mem_ctx, struct ctdb_reply_control reply; struct ctdb_dbid_map *dbmap; struct database *db; - int i; + unsigned int i; reply.rdata.opcode = request->opcode; @@ -2377,7 +2377,7 @@ static void control_reload_nodes_file(TALLOC_CTX *mem_ctx, struct ctdb_reply_control reply; struct ctdb_node_map *nodemap; struct node_map *node_map = ctdb->node_map; - int i; + unsigned int i; reply.rdata.opcode = request->opcode; @@ -2493,7 +2493,7 @@ static void control_release_ip(TALLOC_CTX *mem_ctx, struct ctdb_reply_control reply; struct ctdb_public_ip_list *ips = NULL; struct ctdb_public_ip *t = NULL; - int i; + unsigned int i; reply.rdata.opcode = request->opcode; @@ -2559,7 +2559,7 @@ static void control_takeover_ip(TALLOC_CTX *mem_ctx, struct ctdb_reply_control reply; struct ctdb_public_ip_list *ips = NULL; struct ctdb_public_ip *t = NULL; - int i; + unsigned int i; reply.rdata.opcode = request->opcode; @@ -2663,7 +2663,7 @@ static void control_get_nodemap(TALLOC_CTX *mem_ctx, struct ctdb_reply_control reply; struct ctdb_node_map *nodemap; struct node *node; - int i; + unsigned int i; reply.rdata.opcode = request->opcode; @@ -2954,7 +2954,7 @@ static struct ctdb_iface_list *get_ctdb_iface_list(TALLOC_CTX *mem_ctx, { struct ctdb_iface_list *iface_list; struct interface *iface; - int i; + unsigned int i; iface_list = talloc_zero(mem_ctx, struct ctdb_iface_list); if (iface_list == NULL) { @@ -3745,7 +3745,8 @@ static void client_read_handler(uint8_t *buf, size_t buflen, struct ctdbd_context *ctdb = state->ctdb; struct ctdb_req_header header; size_t np; - int ret, i; + unsigned int i; + int ret; ret = ctdb_req_header_pull(buf, buflen, &header, &np); if (ret != 0) { diff --git a/ctdb/tests/src/fetch_ring.c b/ctdb/tests/src/fetch_ring.c index f746e789511..a8d103ed3f2 100644 --- a/ctdb/tests/src/fetch_ring.c +++ b/ctdb/tests/src/fetch_ring.c @@ -33,7 +33,7 @@ #define MSG_ID_FETCH 0 -static uint32_t next_node(struct ctdb_client_context *client, int num_nodes) +static uint32_t next_node(struct ctdb_client_context *client, uint32_t num_nodes) { return (ctdb_client_pnn(client) + 1) % num_nodes; } @@ -42,7 +42,7 @@ struct fetch_ring_state { struct tevent_context *ev; struct ctdb_client_context *client; struct ctdb_db_context *ctdb_db; - int num_nodes; + uint32_t num_nodes; int timelimit; int interactive; TDB_DATA key; @@ -63,7 +63,7 @@ static struct tevent_req *fetch_ring_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct ctdb_client_context *client, struct ctdb_db_context *ctdb_db, - int num_nodes, int timelimit, + uint32_t num_nodes, int timelimit, int interactive) { struct tevent_req *req, *subreq; diff --git a/ctdb/tests/src/protocol_basic_test.c b/ctdb/tests/src/protocol_basic_test.c index 4bacb47ada3..215c0829854 100644 --- a/ctdb/tests/src/protocol_basic_test.c +++ b/ctdb/tests/src/protocol_basic_test.c @@ -36,7 +36,8 @@ static void test_ctdb_chararray(void) size_t len = rand_int(1000) + 1; char p1[len], p2[len]; size_t buflen, np = 0; - int i, ret; + size_t i; + int ret; for (i=0; igeneration = rand32(); p->size = rand_int(20); @@ -236,7 +236,7 @@ void fill_ctdb_vnn_map(TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *p) void verify_ctdb_vnn_map(struct ctdb_vnn_map *p1, struct ctdb_vnn_map *p2) { - int i; + unsigned int i; assert(p1->generation == p2->generation); assert(p1->size == p2->size); @@ -259,7 +259,7 @@ void verify_ctdb_dbid(struct ctdb_dbid *p1, struct ctdb_dbid *p2) void fill_ctdb_dbid_map(TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *p) { - int i; + unsigned int i; p->num = rand_int(40); if (p->num > 0) { @@ -275,7 +275,7 @@ void fill_ctdb_dbid_map(TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *p) void verify_ctdb_dbid_map(struct ctdb_dbid_map *p1, struct ctdb_dbid_map *p2) { - int i; + unsigned int i; assert(p1->num == p2->num); for (i=0; inum; i++) { @@ -714,7 +714,7 @@ void verify_ctdb_tunable_list(struct ctdb_tunable_list *p1, void fill_ctdb_tickle_list(TALLOC_CTX *mem_ctx, struct ctdb_tickle_list *p) { - int i; + unsigned int i; fill_ctdb_sock_addr(mem_ctx, &p->addr); p->num = rand_int(1000); @@ -732,7 +732,7 @@ void fill_ctdb_tickle_list(TALLOC_CTX *mem_ctx, struct ctdb_tickle_list *p) void verify_ctdb_tickle_list(struct ctdb_tickle_list *p1, struct ctdb_tickle_list *p2) { - int i; + unsigned int i; verify_ctdb_sock_addr(&p1->addr, &p2->addr); assert(p1->num == p2->num); @@ -806,7 +806,7 @@ void verify_ctdb_public_ip(struct ctdb_public_ip *p1, void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx, struct ctdb_public_ip_list *p) { - int i; + unsigned int i; p->num = rand_int(32); if (p->num > 0) { @@ -823,7 +823,7 @@ void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx, void verify_ctdb_public_ip_list(struct ctdb_public_ip_list *p1, struct ctdb_public_ip_list *p2) { - int i; + unsigned int i; assert(p1->num == p2->num); for (i=0; inum; i++) { @@ -849,7 +849,7 @@ void verify_ctdb_node_and_flags(struct ctdb_node_and_flags *p1, void fill_ctdb_node_map(TALLOC_CTX *mem_ctx, struct ctdb_node_map *p) { - int i; + unsigned int i; p->num = rand_int(32); if (p->num > 0) { @@ -866,7 +866,7 @@ void fill_ctdb_node_map(TALLOC_CTX *mem_ctx, struct ctdb_node_map *p) void verify_ctdb_node_map(struct ctdb_node_map *p1, struct ctdb_node_map *p2) { - int i; + unsigned int i; assert(p1->num == p2->num); for (i=0; inum; i++) { @@ -894,7 +894,7 @@ void verify_ctdb_script(struct ctdb_script *p1, struct ctdb_script *p2) void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p) { - int i; + unsigned int i; p->num_scripts = rand_int(32); if (p->num_scripts > 0) { @@ -912,7 +912,7 @@ void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p) void verify_ctdb_script_list(struct ctdb_script_list *p1, struct ctdb_script_list *p2) { - int i; + unsigned int i; assert(p1->num_scripts == p2->num_scripts); for (i=0; inum_scripts; i++) { @@ -962,7 +962,7 @@ void verify_ctdb_iface(struct ctdb_iface *p1, struct ctdb_iface *p2) void fill_ctdb_iface_list(TALLOC_CTX *mem_ctx, struct ctdb_iface_list *p) { - int i; + unsigned int i; p->num = rand_int(32); if (p->num > 0) { @@ -979,7 +979,7 @@ void fill_ctdb_iface_list(TALLOC_CTX *mem_ctx, struct ctdb_iface_list *p) void verify_ctdb_iface_list(struct ctdb_iface_list *p1, struct ctdb_iface_list *p2) { - int i; + unsigned int i; assert(p1->num == p2->num); for (i=0; inum; i++) { @@ -1052,7 +1052,7 @@ void verify_ctdb_key_data(struct ctdb_key_data *p1, struct ctdb_key_data *p2) void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx, struct ctdb_db_statistics *p) { - int i; + unsigned int i; p->locks.num_calls = rand32(); p->locks.num_current = rand32(); @@ -1081,7 +1081,7 @@ void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx, void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1, struct ctdb_db_statistics *p2) { - int i; + unsigned int i; assert(p1->locks.num_calls == p2->locks.num_calls); assert(p1->locks.num_current == p2->locks.num_current); @@ -1199,7 +1199,7 @@ void verify_ctdb_g_lock(struct ctdb_g_lock *p1, struct ctdb_g_lock *p2) void fill_ctdb_g_lock_list(TALLOC_CTX *mem_ctx, struct ctdb_g_lock_list *p) { - int i; + unsigned int i; p->num = rand_int(20) + 1; p->lock = talloc_zero_array(mem_ctx, struct ctdb_g_lock, p->num); @@ -1212,7 +1212,7 @@ void fill_ctdb_g_lock_list(TALLOC_CTX *mem_ctx, struct ctdb_g_lock_list *p) void verify_ctdb_g_lock_list(struct ctdb_g_lock_list *p1, struct ctdb_g_lock_list *p2) { - int i; + unsigned int i; assert(p1->num == p2->num); for (i=0; inum; i++) { diff --git a/ctdb/tests/src/protocol_common_basic.c b/ctdb/tests/src/protocol_common_basic.c index cbc59606629..b8b82fd298c 100644 --- a/ctdb/tests/src/protocol_common_basic.c +++ b/ctdb/tests/src/protocol_common_basic.c @@ -70,7 +70,7 @@ double rand_double(void) void fill_buffer(void *p, size_t len) { - int i; + size_t i; uint8_t *ptr = p; for (i=0; iaddr, &in->addr, sizeof(ctdb_sock_addr)); wire->num = in->num; @@ -987,7 +987,8 @@ static int ctdb_tickle_list_pull_old(uint8_t *buf, size_t buflen, struct ctdb_tickle_list_wire *wire = (struct ctdb_tickle_list_wire *)buf; size_t offset; - int i, ret; + unsigned int i; + int ret; if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) { return EMSGSIZE; @@ -1220,7 +1221,7 @@ struct ctdb_public_ip_list_wire { static size_t ctdb_public_ip_list_len_old(struct ctdb_public_ip_list *in) { - int i; + unsigned int i; size_t len; len = sizeof(uint32_t); @@ -1236,7 +1237,7 @@ static void ctdb_public_ip_list_push_old(struct ctdb_public_ip_list *in, struct ctdb_public_ip_list_wire *wire = (struct ctdb_public_ip_list_wire *)buf; size_t offset; - int i; + unsigned int i; wire->num = in->num; @@ -1255,7 +1256,7 @@ static int ctdb_public_ip_list_pull_old(uint8_t *buf, size_t buflen, struct ctdb_public_ip_list_wire *wire = (struct ctdb_public_ip_list_wire *)buf; size_t offset; - int i; + unsigned int i; bool ret; if (buflen < sizeof(uint32_t)) { @@ -1368,7 +1369,7 @@ static void ctdb_node_map_push_old(struct ctdb_node_map *in, uint8_t *buf) { struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf; size_t offset; - int i; + unsigned int i; wire->num = in->num; @@ -1386,7 +1387,7 @@ static int ctdb_node_map_pull_old(uint8_t *buf, size_t buflen, struct ctdb_node_map *val; struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf; size_t offset; - int i; + unsigned int i; bool ret; if (buflen < sizeof(uint32_t)) { @@ -1484,7 +1485,7 @@ struct ctdb_script_list_wire { static size_t ctdb_script_list_len_old(struct ctdb_script_list *in) { - int i; + unsigned int i; size_t len; if (in == NULL) { @@ -1504,7 +1505,7 @@ static void ctdb_script_list_push_old(struct ctdb_script_list *in, struct ctdb_script_list_wire *wire = (struct ctdb_script_list_wire *)buf; size_t offset; - int i; + unsigned int i; if (in == NULL) { return; @@ -1527,7 +1528,7 @@ static int ctdb_script_list_pull_old(uint8_t *buf, size_t buflen, struct ctdb_script_list_wire *wire = (struct ctdb_script_list_wire *)buf; size_t offset; - int i; + unsigned int i; bool ret; /* If event scripts have never been run, the result will be NULL */ @@ -2024,7 +2025,7 @@ static int ctdb_db_statistics_pull_old(uint8_t *buf, size_t buflen, struct ctdb_db_statistics_wire *wire = (struct ctdb_db_statistics_wire *)buf; size_t offset; - int i; + unsigned int i; if (buflen < sizeof(struct ctdb_db_statistics)) { return EMSGSIZE; @@ -2220,7 +2221,7 @@ static void ctdb_g_lock_list_push_old(struct ctdb_g_lock_list *in, uint8_t *buf) { size_t offset = 0; - int i; + unsigned int i; for (i=0; inum; i++) { ctdb_g_lock_push_old(&in->lock[i], &buf[offset]); @@ -2235,7 +2236,8 @@ static int ctdb_g_lock_list_pull_old(uint8_t *buf, size_t buflen, struct ctdb_g_lock_list *val; unsigned count; size_t offset; - int ret, i; + unsigned int i; + int ret; val = talloc_zero(mem_ctx, struct ctdb_g_lock_list); if (val == NULL) { diff --git a/ctdb/tests/src/run_event_test.c b/ctdb/tests/src/run_event_test.c index 8b5dcd7beef..cfe5f161d1d 100644 --- a/ctdb/tests/src/run_event_test.c +++ b/ctdb/tests/src/run_event_test.c @@ -60,7 +60,8 @@ static void do_run(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct timeval timeout; struct run_event_script_list *script_list = NULL; char *arg_str; - int ret, t, i; + unsigned int i; + int ret, t; bool status; if (argc < 5) { @@ -115,7 +116,8 @@ static void do_list(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int argc, const char **argv) { struct run_event_script_list *script_list = NULL; - int ret, i; + unsigned int i; + int ret; ret = run_event_list(run_ctx, mem_ctx, &script_list); if (ret != 0) { diff --git a/ctdb/tests/src/sigcode.c b/ctdb/tests/src/sigcode.c index 1318d246891..9e5ed819f8e 100644 --- a/ctdb/tests/src/sigcode.c +++ b/ctdb/tests/src/sigcode.c @@ -58,7 +58,7 @@ struct { static void dump(void) { - int i; + size_t i; for (i=0; i