From e0fcf99b6021e98fb5f6580fba89d5fb4276946a Mon Sep 17 00:00:00 2001
From: Alexey Marchuk <alexeymar@mellanox.com>
Date: Wed, 14 Apr 2021 11:27:38 +0300
Subject: [PATCH] ut/rdma: Fix GCC 10.2.0 warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

rdma_ut.c: In function ‘test_spdk_nvmf_rdma_request_parse_sgl_with_md’:
rdma_ut.c:1152:54: warning: array subscript 10 is outside array bounds of ‘struct spdk_nvmf_rdma_request_data[1]’ [-Warray-bounds]
 1152 |  aligned_buffer = (void *)((uintptr_t)((char *)&data + NVMF_DATA_BUFFER_MASK) &
      |                                       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
rdma_ut.c:834:37: note: while referencing ‘data’
  834 |  struct spdk_nvmf_rdma_request_data data;
      |                                     ^~~~

The fix is to use array instead of spdk_nvmf_rdma_request_data
structure

Change-Id: I81bd311d26037dcb9340d85abcb4ea45b20a5171
Reported-by: G.Balaji <gbalajieie@gmail.com>
Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7365
Community-CI: Broadcom CI
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
---
 test/unit/lib/nvmf/rdma.c/rdma_ut.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/test/unit/lib/nvmf/rdma.c/rdma_ut.c b/test/unit/lib/nvmf/rdma.c/rdma_ut.c
index 8674f52..eb46a4c 100644
--- a/test/unit/lib/nvmf/rdma.c/rdma_ut.c
+++ b/test/unit/lib/nvmf/rdma.c/rdma_ut.c
@@ -836,7 +836,8 @@ test_spdk_nvmf_rdma_request_parse_sgl_with_md(void)
 	union nvmf_h2c_msg cmd;
 	struct spdk_nvme_sgl_descriptor *sgl;
 	struct spdk_nvme_sgl_descriptor sgl_desc[SPDK_NVMF_MAX_SGL_ENTRIES] = {{0}};
-	struct spdk_nvmf_rdma_request_data data;
+	char data_buffer[8192];
+	struct spdk_nvmf_rdma_request_data *data = (struct spdk_nvmf_rdma_request_data *)data_buffer;
 	char data2_buffer[8192];
 	struct spdk_nvmf_rdma_request_data *data2 = (struct spdk_nvmf_rdma_request_data *)data2_buffer;
 	const uint32_t data_bs = 512;
@@ -844,7 +845,7 @@ test_spdk_nvmf_rdma_request_parse_sgl_with_md(void)
 	int rc, i;
 	void *aligned_buffer;
 
-	data.wr.sg_list = data.sgl;
+	data->wr.sg_list = data->sgl;
 	STAILQ_INIT(&group.group.buf_cache);
 	group.group.buf_cache_size = 0;
 	group.group.buf_cache_count = 0;
@@ -1153,8 +1154,8 @@ test_spdk_nvmf_rdma_request_parse_sgl_with_md(void)
 	sgl->unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
 	sgl->address = 0;
 	rdma_req.recv->buf = (void *)&sgl_desc;
-	MOCK_SET(spdk_mempool_get, &data);
-	aligned_buffer = (void *)((uintptr_t)((char *)&data + NVMF_DATA_BUFFER_MASK) &
+	MOCK_SET(spdk_mempool_get, data_buffer);
+	aligned_buffer = (void *)((uintptr_t)(data_buffer + NVMF_DATA_BUFFER_MASK) &
 				  ~NVMF_DATA_BUFFER_MASK);
 
 	/* part 1: 2 segments each with 1 wr. io_unit_size is aligned with data_bs + md_size */
@@ -1190,17 +1191,17 @@ test_spdk_nvmf_rdma_request_parse_sgl_with_md(void)
 
 	CU_ASSERT(rdma_req.data.wr.wr.rdma.rkey == 0x44);
 	CU_ASSERT(rdma_req.data.wr.wr.rdma.remote_addr == 0x4000);
-	CU_ASSERT(rdma_req.data.wr.next == &data.wr);
-	CU_ASSERT(data.wr.wr.rdma.rkey == 0x44);
-	CU_ASSERT(data.wr.wr.rdma.remote_addr == 0x4000 + data_bs * 4);
-	CU_ASSERT(data.wr.num_sge == 4);
+	CU_ASSERT(rdma_req.data.wr.next == &data->wr);
+	CU_ASSERT(data->wr.wr.rdma.rkey == 0x44);
+	CU_ASSERT(data->wr.wr.rdma.remote_addr == 0x4000 + data_bs * 4);
+	CU_ASSERT(data->wr.num_sge == 4);
 	for (i = 0; i < 4; ++i) {
-		CU_ASSERT(data.wr.sg_list[i].addr == (uintptr_t)((unsigned char *)aligned_buffer) + i *
+		CU_ASSERT(data->wr.sg_list[i].addr == (uintptr_t)((unsigned char *)aligned_buffer) + i *
 			  (data_bs + md_size));
-		CU_ASSERT(data.wr.sg_list[i].length == data_bs);
+		CU_ASSERT(data->wr.sg_list[i].length == data_bs);
 	}
 
-	CU_ASSERT(data.wr.next == &rdma_req.rsp.wr);
+	CU_ASSERT(data->wr.next == &rdma_req.rsp.wr);
 }
 
 int main(int argc, char **argv)
-- 
2.27.0

