klocwork fixes
authorNathan S. Evans <evans@in.tum.de>
Wed, 1 Sep 2010 13:21:03 +0000 (13:21 +0000)
committerNathan S. Evans <evans@in.tum.de>
Wed, 1 Sep 2010 13:21:03 +0000 (13:21 +0000)
src/testing/test_testing_group_remote.c
src/testing/test_testing_topology.c
src/testing/test_testing_topology_blacklist.c
src/testing/test_testing_topology_churn.c
src/testing/testing.c
src/testing/testing_group.c

index b4d04fdd8b170ed509b626dee090fe4b39686a79..a58a1234e0709092a218a900cdf420384e5f0c3a 100644 (file)
@@ -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);
 }
 
index 3d03d76117d2fca36310130c9310659faf0cec6b..af4a6a39f0c6403df09c41880fa6effb6a9c8da3 100644 (file)
@@ -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);
index dab06de9081a25664886fef060e968ecd3a0c003..5e35205101875a91d6ce2633e7d4e06b99868014 100644 (file)
@@ -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
index 880b0fefc250d2d6fb4475fdb464df3623a4c04d..a4b80e4a467d54166de83b7a748297093c08920c 100644 (file)
@@ -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
index 3ad3f955c4884bf452b15098912750deed2aa3d1..2e4a44b2d608eea900850a0cd3e3cbd632a93d3d 100644 (file)
@@ -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));
index 2d17ecb623a53217deee04e662846e6def0b26e2..30efc4985bf2ce43c7923cfe853b2f9fd51c0e94 100644 (file)
@@ -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)