From 766afaaacc87fb384bfb8270307fa065b50b7d01 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 24 Sep 2015 12:59:55 -0700 Subject: [PATCH] nvme/test: avoid clang warnings in nvme_ns_cmd_ut Initialize the full nvme_namespace structure in prepare_for_test() so that e.g. ns->id is not used uninitialized. Also check for request allocation failure - if the request is NULL, we can't run the rest of the tests that dereference request without crashing. Change-Id: I3010ca3e81f153a4d0201498a14a963c2b9e960d Signed-off-by: Daniel Verkamp --- test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c b/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c index e40d4e352..75c676474 100644 --- a/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c +++ b/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c @@ -94,6 +94,7 @@ prepare_for_test(struct nvme_namespace *ns, struct nvme_controller *ctrlr, uint32_t stripe_size) { ctrlr->max_xfer_size = max_xfer_size; + memset(ns, 0, sizeof(*ns)); ns->ctrlr = ctrlr; ns->sector_size = sector_size; ns->stripe_size = stripe_size; @@ -122,8 +123,11 @@ split_test(void) CU_ASSERT(rc == 0); CU_ASSERT(g_request != NULL); - CU_ASSERT(g_request->num_children == 0); + if (g_request == NULL) { + return; /* can't run the rest of the tests without crashing if this failed */ + } + CU_ASSERT(g_request->num_children == 0); nvme_free_request(g_request); } @@ -147,6 +151,10 @@ split_test2(void) CU_ASSERT(rc == 0); CU_ASSERT(g_request != NULL); + if (g_request == NULL) { + return; /* can't run the rest of the tests without crashing if this failed */ + } + CU_ASSERT(g_request->num_children == 2); child = TAILQ_FIRST(&g_request->children);