From 8cf89dc53789e4b99d18db5e575819b21d8b2c36 Mon Sep 17 00:00:00 2001 From: Gordon Wang <36049150+gordonwang0@users.noreply.github.com> Date: Fri, 20 Apr 2018 15:07:43 -0700 Subject: [PATCH] Fix integration test bugs reported by Coverity. --- src/aws_iot_mqtt_client.c | 2 +- src/aws_iot_shadow.c | 2 +- .../aws_iot_test_multithreading_validation.c | 8 +++++--- tests/integration/src/aws_iot_test_auto_reconnect.c | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/aws_iot_mqtt_client.c b/src/aws_iot_mqtt_client.c index 727e442125..6dcd15f540 100644 --- a/src/aws_iot_mqtt_client.c +++ b/src/aws_iot_mqtt_client.c @@ -194,7 +194,7 @@ IoT_Error_t aws_iot_mqtt_free(AWS_IoT_Client *pClient) { rc = aws_iot_thread_mutex_destroy(&(pClient->clientData.tls_write_mutex)); }else{ - (void)aws_iot_thread_mutex_destroy(&(pClient->clientData.tls_read_mutex)); + (void)aws_iot_thread_mutex_destroy(&(pClient->clientData.tls_write_mutex)); } #endif } diff --git a/src/aws_iot_shadow.c b/src/aws_iot_shadow.c index a6997029a0..5c69edb05d 100644 --- a/src/aws_iot_shadow.c +++ b/src/aws_iot_shadow.c @@ -70,7 +70,7 @@ IoT_Error_t aws_iot_shadow_free(AWS_IoT_Client *pClient) } IoT_Error_t aws_iot_shadow_init(AWS_IoT_Client *pClient, ShadowInitParameters_t *pParams) { - IoT_Client_Init_Params mqttInitParams; + IoT_Client_Init_Params mqttInitParams = IoT_Client_Init_Params_initializer; IoT_Error_t rc; FUNC_ENTRY; diff --git a/tests/integration/multithreadingTest/aws_iot_test_multithreading_validation.c b/tests/integration/multithreadingTest/aws_iot_test_multithreading_validation.c index f49b6888a4..369a79eb8d 100644 --- a/tests/integration/multithreadingTest/aws_iot_test_multithreading_validation.c +++ b/tests/integration/multithreadingTest/aws_iot_test_multithreading_validation.c @@ -181,6 +181,8 @@ static void *aws_iot_mqtt_tests_sub_unsub_thread_runner(void *ptr) { IOT_ERROR("Unsubscribe Returned : %d ", rc); } } + + return NULL; } int aws_iot_mqtt_tests_multi_threading_validation() { @@ -192,7 +194,7 @@ int aws_iot_mqtt_tests_multi_threading_validation() { char root_CA[PATH_MAX + 1]; char clientId[50]; - IoT_Client_Init_Params initParams; + IoT_Client_Init_Params initParams = IoT_Client_Init_Params_initializer; IoT_Client_Connect_Params connectParams; int threadId[MAX_PUB_THREAD_COUNT]; int pubThreadReturn[MAX_PUB_THREAD_COUNT]; @@ -201,7 +203,7 @@ int aws_iot_mqtt_tests_multi_threading_validation() { int finishedThreadCount = 0; IoT_Error_t rc = SUCCESS; int i, rxMsgCount = 0, j = 0; - struct timeval connectTime, subscribeTopic; + struct timeval subscribeTopic; unsigned int connectCounter = 0; int test_result = 0; ThreadData threadData[MAX_PUB_THREAD_COUNT]; @@ -262,7 +264,7 @@ int aws_iot_mqtt_tests_multi_threading_validation() { } while(SUCCESS != rc && connectCounter < CONNECT_MAX_ATTEMPT_COUNT); if(SUCCESS == rc) { - printf("\n## Connect Success. Time sec: %d, usec: %d\n", connectTime.tv_sec, connectTime.tv_usec); + printf("\n## Connect Success.\n"); } else { IOT_ERROR("## Connect Failed. error code %d\n", rc); return -1; diff --git a/tests/integration/src/aws_iot_test_auto_reconnect.c b/tests/integration/src/aws_iot_test_auto_reconnect.c index c314802951..267d9dc050 100644 --- a/tests/integration/src/aws_iot_test_auto_reconnect.c +++ b/tests/integration/src/aws_iot_test_auto_reconnect.c @@ -39,7 +39,7 @@ void aws_iot_mqtt_tests_block_tls_connect(AWS_IoT_Client *pClient) { /** * Always ensure this function is called after block_tls_connect */ -int aws_iot_mqtt_tests_unblock_tls_connect(AWS_IoT_Client *pClient) { +void aws_iot_mqtt_tests_unblock_tls_connect(AWS_IoT_Client *pClient) { pClient->networkStack.tlsConnectParams.pRootCALocation = savedLocation; } @@ -62,6 +62,8 @@ void *aws_iot_mqtt_tests_yield_with_rc(void *ptr) { yieldRC = rc; } } + + return NULL; } unsigned int disconnectedCounter = 0; @@ -91,7 +93,7 @@ int aws_iot_mqtt_tests_auto_reconnect() { snprintf(clientId, 50, "%s_%d", INTEGRATION_TEST_CLIENT_ID, rand() % 10000); printf(" Root CA Path : %s\n clientCRT : %s\n clientKey : %s\n", root_CA, clientCRT, clientKey); - IoT_Client_Init_Params initParams; + IoT_Client_Init_Params initParams = IoT_Client_Init_Params_initializer; initParams.pHostURL = AWS_IOT_MQTT_HOST; initParams.port = AWS_IOT_MQTT_PORT; initParams.pRootCALocation = root_CA;