From 930871b49ea5ba14a92c6c0ed8e3ecc648da0b22 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Wed, 1 Sep 2010 13:21:03 +0000 Subject: [PATCH] klocwork fixes --- src/testing/test_testing_group_remote.c | 11 ++++++++++ src/testing/test_testing_topology.c | 5 +++-- src/testing/test_testing_topology_blacklist.c | 1 + src/testing/test_testing_topology_churn.c | 1 + src/testing/testing.c | 8 +++++--- src/testing/testing_group.c | 20 ++++++++++++++++--- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c index b4d04fdd8..a58a1234e 100644 --- a/src/testing/test_testing_group_remote.c +++ b/src/testing/test_testing_group_remote.c @@ -106,6 +106,7 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_TESTING_Host *hosts; + struct GNUNET_TESTING_Host *hostpos; struct GNUNET_TESTING_Host *temphost; char *hostfile; struct stat frstat; @@ -123,12 +124,14 @@ run (void *cls, &num_peers)) num_peers = DEFAULT_NUM_PEERS; + GNUNET_assert(num_peers > 0 && num_peers < (unsigned long long)-1); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile", &hostfile)) hostfile = NULL; hosts = NULL; + data = NULL; if (hostfile != NULL) { if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) @@ -188,6 +191,14 @@ run (void *cls, NULL, NULL, hosts); + hostpos = hosts; + while (hostpos != NULL) + { + temphost = hostpos->next; + GNUNET_free(hostpos); + hostpos = temphost; + } + GNUNET_free_non_null(data); GNUNET_assert (pg != NULL); } diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index 3d03d7611..af4a6a39f 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -200,8 +200,6 @@ finish_testing () "Called finish testing, stopping daemons.\n"); #endif - int count; - count = 0; pos = test_messages; while (pos != NULL) { @@ -377,6 +375,7 @@ process_mtype (void *cls, GNUNET_SCHEDULER_cancel (sched, die_task); GNUNET_asprintf(&dotOutFileNameFinished, "%s.dot", "final_topology"); dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); + GNUNET_free(dotOutFileNameFinished); if (dotOutFileFinished != NULL) { fprintf(dotOutFileFinished, "strict graph G {\n"); @@ -1001,6 +1000,7 @@ run (void *cls, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!"); + GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); pg = GNUNET_TESTING_daemons_start (sched, cfg, peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL, &topology_callback, NULL, NULL); @@ -1046,6 +1046,7 @@ main (int argc, char *argv[]) char *our_binary_name; binary_start_pos = rindex(argv[0], '/'); + GNUNET_assert(binary_start_pos != NULL); topology_string = strstr (binary_start_pos, "_topology"); GNUNET_assert (topology_string != NULL); diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c index dab06de90..5e3520510 100644 --- a/src/testing/test_testing_topology_blacklist.c +++ b/src/testing/test_testing_topology_blacklist.c @@ -470,6 +470,7 @@ run (void *cls, main_cfg = cfg; + GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); peers_left = num_peers; /* For this specific test we only really want a CLIQUE topology as the diff --git a/src/testing/test_testing_topology_churn.c b/src/testing/test_testing_topology_churn.c index 880b0fefc..a4b80e4a4 100644 --- a/src/testing/test_testing_topology_churn.c +++ b/src/testing/test_testing_topology_churn.c @@ -266,6 +266,7 @@ run (void *cls, main_cfg = cfg; peers_left = num_peers; + GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); /* For this specific test we only really want a CLIQUE topology as the * overlay allowed topology, and a RING topology as the underlying connection diff --git a/src/testing/testing.c b/src/testing/testing.c index 3ad3f955c..2e4a44b2d 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -1338,13 +1338,15 @@ static void send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ConnectContext *ctx = cls; - + struct GNUNET_MessageHeader *hello; ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) return; - if (ctx->d1->hello != NULL) + if ((ctx->d1->hello != NULL) && (NULL != GNUNET_HELLO_get_header(ctx->d1->hello))) { - GNUNET_TRANSPORT_offer_hello (ctx->d2th, GNUNET_HELLO_get_header(ctx->d1->hello)); + hello = GNUNET_HELLO_get_header(ctx->d1->hello); + GNUNET_assert(hello != NULL); + GNUNET_TRANSPORT_offer_hello (ctx->d2th, hello); ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)); diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 2d17ecb62..30efc4985 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -1306,6 +1306,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti unsigned int distance; double probability, random, percentage; unsigned int smallWorldConnections; + unsigned int small_world_it; char *p_string; int connect_attempts; square = floor (sqrt (pg->total)); @@ -1326,6 +1327,13 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti "TESTING"); GNUNET_free (p_string); } + if (percentage < 0.0) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), + "PERCENTAGE", "TESTING", percentage); + percentage = 0.5; + } probability = 0.5; /* FIXME: default percentage? */ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, "TESTING", @@ -1392,7 +1400,9 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Total connections added thus far: %u!\n"), connect_attempts); #endif smallWorldConnections = 0; - for (i = 0; i < (int) (natLog * percentage); i++) + small_world_it = (unsigned int)(natLog * percentage); + GNUNET_assert(small_world_it > 0 && small_world_it < (unsigned int)-1); + for (i = 0; i < small_world_it; i++) { for (j = 0; j < pg->total; j++) { @@ -2247,7 +2257,6 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, int unblacklisted_connections; GNUNET_assert (pg->notify_connection != NULL); - ret = GNUNET_OK; switch (topology) { @@ -3797,22 +3806,26 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, } } + GNUNET_assert(running >= voff); for (i = 0; i < voff; i++) { #if DEBUG_CHURN GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", running_permute[i]); #endif + GNUNET_assert(running_arr != NULL); GNUNET_TESTING_daemon_stop (pg->peers[running_arr[running_permute[i]]].daemon, timeout, &churn_stop_callback, churn_ctx, GNUNET_NO, GNUNET_YES); } + GNUNET_assert(stopped >= von); for (i = 0; i < von; i++) { #if DEBUG_CHURN GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", stopped_permute[i]); #endif + GNUNET_assert(stopped_arr != NULL); GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, timeout, &churn_start_callback, churn_ctx); } @@ -3964,9 +3977,10 @@ static void schedule_shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) { struct PeerShutdownContext *peer_shutdown_ctx = cls; - struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; + struct ShutdownContext *shutdown_ctx; GNUNET_assert(peer_shutdown_ctx != NULL); + shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; GNUNET_assert(shutdown_ctx != NULL); if (shutdown_ctx->outstanding > MAX_CONCURRENT_SHUTDOWN) -- 2.25.1