From: Nathan S. Evans Date: Mon, 21 Jun 2010 14:30:08 +0000 (+0000) Subject: codesonar fixes X-Git-Tag: initial-import-from-subversion-38251~21309 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b50484f5af8f9a33ecea9cef21621cd71d78b25d;p=oweals%2Fgnunet.git codesonar fixes --- diff --git a/src/testing/testing.c b/src/testing/testing.c index 5b36fc380..58d09806b 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -65,6 +65,7 @@ static void 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 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) } 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 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) "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; + } } } diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index b304047ba..de624f25f 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -3150,6 +3150,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, 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,8 +3196,14 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, } 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 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, 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 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, { 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 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, 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); }