gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r11847 - gnunet/src/testing


From: gnunet
Subject: [GNUnet-SVN] r11847 - gnunet/src/testing
Date: Mon, 21 Jun 2010 16:30:08 +0200

Author: nevans
Date: 2010-06-21 16:30:08 +0200 (Mon, 21 Jun 2010)
New Revision: 11847

Modified:
   gnunet/src/testing/testing.c
   gnunet/src/testing/testing_group.c
Log:
codesonar fixes

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2010-06-21 11:39:46 UTC (rev 11846)
+++ gnunet/src/testing/testing.c        2010-06-21 14:30:08 UTC (rev 11847)
@@ -65,6 +65,7 @@
 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TESTING_Daemon *daemon = cls;
+  int msize;
   if (daemon == NULL)
     return;
 
@@ -75,6 +76,11 @@
     }
 
   GNUNET_assert (message != NULL);
+  msize = ntohs(message->size);
+  if (msize < 1)
+    {
+      return;
+    }
   if (daemon->th != NULL)
     {
       GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon);
@@ -85,14 +91,18 @@
               "HELLO", GNUNET_i2s (&daemon->id));
 #endif
 
-  GNUNET_free_non_null(daemon->hello);
-  daemon->hello = GNUNET_malloc(ntohs(message->size));
-  memcpy(daemon->hello, message, ntohs(message->size));
 
-  if (daemon->th != NULL)
+
     {
-      GNUNET_TRANSPORT_disconnect(daemon->th);
-      daemon->th = NULL;
+      GNUNET_free_non_null(daemon->hello);
+      daemon->hello = GNUNET_malloc(msize);
+      memcpy(daemon->hello, message, msize);
+
+      if (daemon->th != NULL)
+        {
+          GNUNET_TRANSPORT_disconnect(daemon->th);
+          daemon->th = NULL;
+        }
     }
 
 }

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2010-06-21 11:39:46 UTC (rev 11846)
+++ gnunet/src/testing/testing_group.c  2010-06-21 14:30:08 UTC (rev 11847)
@@ -3150,6 +3150,8 @@
   struct ChurnContext *churn_ctx;
   unsigned int running;
   unsigned int stopped;
+  unsigned int total_running;
+  unsigned int total_stopped;
   unsigned int i;
   unsigned int *running_arr;
   unsigned int *stopped_arr;
@@ -3194,9 +3196,15 @@
   }
 
   churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
-  running_arr = GNUNET_malloc(running * sizeof(unsigned int));
-  stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int));
 
+  running_arr = NULL;
+  if (running > 0)
+    running_arr = GNUNET_malloc(running * sizeof(unsigned int));
+
+  stopped_arr = NULL;
+  if (stopped > 0)
+    stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int));
+
   running_permute = NULL;
   stopped_permute = NULL;
 
@@ -3205,6 +3213,8 @@
   if (stopped > 0)
     stopped_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, 
stopped);
 
+  total_running = running;
+  total_stopped = stopped;
   running = 0;
   stopped = 0;
 
@@ -3217,11 +3227,13 @@
   {
     if (pg->peers[i].daemon->running == GNUNET_YES)
     {
+      GNUNET_assert((running_arr != NULL) && (total_running > running));
       running_arr[running] = i;
       running++;
     }
     else
     {
+      GNUNET_assert((stopped_arr != NULL) && (total_stopped > stopped));
       stopped_arr[stopped] = i;
       stopped++;
     }
@@ -3247,8 +3259,8 @@
                                          timeout, &churn_start_callback, 
churn_ctx);
   }
 
-  GNUNET_free(running_arr);
-  GNUNET_free(stopped_arr);
+  GNUNET_free_non_null(running_arr);
+  GNUNET_free_non_null(stopped_arr);
   GNUNET_free_non_null(running_permute);
   GNUNET_free_non_null(stopped_permute);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]