From 71124c49eef29c3fdc6279466ee81a018b4d487a Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Tue, 6 Feb 2018 02:26:35 +0100 Subject: [PATCH] tests: avoid triggering -Wstringop-truncation in ioctl_dm.c * tests/ioctl_dm.c: Replace strncpy calls with memcpy as the character arrays being copied are not C strings. --- tests/ioctl_dm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ioctl_dm.c b/tests/ioctl_dm.c index 1e831dfe..d9bf20ed 100644 --- a/tests/ioctl_dm.c +++ b/tests/ioctl_dm.c @@ -143,7 +143,7 @@ init_dm_target_spec(struct dm_target_spec *ptr, uint32_t id) ptr->length = dts_length_base + dts_length_step * id; ptr->status = dts_status_base + dts_status_step * id; - strncpy(ptr->target_type, str129 + + memcpy(ptr->target_type, str129 + id % (sizeof(str129) - sizeof(ptr->target_type)), id % (sizeof(ptr->target_type) + 1)); if (id % (sizeof(ptr->target_type) + 1) < sizeof(ptr->target_type)) @@ -252,8 +252,8 @@ main(void) /* Unterminated name/uuid */ init_s(dm_arg, min_sizeof_dm_ioctl, 0); - strncpy(dm_arg->name, str129, sizeof(dm_arg->name)); - strncpy(dm_arg->uuid, str129, sizeof(dm_arg->uuid)); + memcpy(dm_arg->name, str129, sizeof(dm_arg->name)); + memcpy(dm_arg->uuid, str129, sizeof(dm_arg->uuid)); ioctl(-1, DM_VERSION, dm_arg); printf("ioctl(-1, DM_VERSION, {version=4.1.2, data_size=%zu, " "dev=makedev(18, 52), name=\"%.127s\"..., uuid=\"%.128s\"..., " @@ -511,7 +511,7 @@ main(void) target##id_next) - \ offsetof(struct dm_table_open_test, \ target##id); \ - strncpy(dm_arg_open3->param##id, str129 + id * 2, id); \ + memcpy(dm_arg_open3->param##id, str129 + id * 2, id); \ dm_arg_open3->param##id[id] = '\0'; \ } while (0) #define PRINT_DM_TARGET(id) \ -- 2.40.0