From d490572410ae9eb1cd207cb3a4818cc2e5c2ad0b Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 8 Apr 2024 14:10:18 +0200 Subject: [PATCH] gcc: clear some complains Use dm_strncpy() were possible to get rid of gcc compile warnings. --- daemons/lvmlockd/lvmlockd-core.c | 10 +++++----- daemons/lvmlockd/lvmlockd-sanlock.c | 5 ++--- device_mapper/libdm-deptree.c | 4 ++-- lib/device/online.c | 4 ++-- libdm/libdm-deptree.c | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c index 1f594041d..504b2969e 100644 --- a/daemons/lvmlockd/lvmlockd-core.c +++ b/daemons/lvmlockd/lvmlockd-core.c @@ -2984,10 +2984,10 @@ static int add_lockspace_thread(const char *ls_name, strncpy(ls->vg_uuid, vg_uuid, 64); if (vg_name) - strncpy(ls->vg_name, vg_name, MAX_NAME); + dm_strncpy(ls->vg_name, vg_name, sizeof(ls->vg_name)); if (vg_args) - strncpy(ls->vg_args, vg_args, MAX_ARGS); + dm_strncpy(ls->vg_args, vg_args, sizeof(ls->vg_args)); if (act) ls->host_id = act->host_id; @@ -4906,13 +4906,13 @@ static void client_recv_action(struct client *cl) act->path = strdup(path); if (vg_name && strcmp(vg_name, "none")) - strncpy(act->vg_name, vg_name, MAX_NAME); + dm_strncpy(act->vg_name, vg_name, sizeof(act->vg_name)); if (vg_uuid && strcmp(vg_uuid, "none")) strncpy(act->vg_uuid, vg_uuid, 64); if (vg_sysid && strcmp(vg_sysid, "none")) - strncpy(act->vg_sysid, vg_sysid, MAX_NAME); + dm_strncpy(act->vg_sysid, vg_sysid, sizeof(act->vg_sysid)); str = daemon_request_str(req, "lv_name", NULL); if (str && strcmp(str, "none")) @@ -5627,7 +5627,7 @@ static void adopt_locks(void) act->rt = LD_RT_VG; act->lm_type = ls->lm_type; act->client_id = INTERNAL_CLIENT_ID; - strncpy(act->vg_name, ls->vg_name, MAX_NAME); + dm_strncpy(act->vg_name, ls->vg_name, sizeof(act->vg_name)); memcpy(act->vg_uuid, ls->vg_uuid, 64); memcpy(act->vg_args, ls->vg_args, MAX_ARGS); act->host_id = ls->host_id; diff --git a/daemons/lvmlockd/lvmlockd-sanlock.c b/daemons/lvmlockd/lvmlockd-sanlock.c index c7158e3d8..00347bfba 100644 --- a/daemons/lvmlockd/lvmlockd-sanlock.c +++ b/daemons/lvmlockd/lvmlockd-sanlock.c @@ -1339,7 +1339,7 @@ int lm_prepare_lockspace_sanlock(struct lockspace *ls) struct stat st; struct lm_sanlock *lms = NULL; char lock_lv_name[MAX_ARGS+1]; - char lsname[SANLK_NAME_LEN + 1]; + char lsname[SANLK_NAME_LEN + 1] = { 0 }; char disk_path[SANLK_PATH_LEN]; char killpath[SANLK_PATH_LEN]; char killargs[SANLK_PATH_LEN]; @@ -1420,8 +1420,7 @@ int lm_prepare_lockspace_sanlock(struct lockspace *ls) goto fail; } - memset(lsname, 0, sizeof(lsname)); - strncpy(lsname, ls->name, SANLK_NAME_LEN); + dm_strncpy(lsname, ls->name, sizeof(lsname)); memcpy(lms->ss.name, lsname, SANLK_NAME_LEN); lms->ss.host_id_disk.offset = 0; diff --git a/device_mapper/libdm-deptree.c b/device_mapper/libdm-deptree.c index 6ca34354d..448d6f418 100644 --- a/device_mapper/libdm-deptree.c +++ b/device_mapper/libdm-deptree.c @@ -598,7 +598,7 @@ static struct dm_tree_node *_find_dm_tree_node_by_uuid(struct dm_tree *dtree, const char *default_uuid_prefix; size_t default_uuid_prefix_len; const char *suffix, *suffix_position; - char uuid_without_suffix[DM_UUID_LEN]; + char uuid_without_suffix[DM_UUID_LEN + 1]; unsigned i = 0; const char **suffix_list = dtree->optional_uuid_suffixes; @@ -612,7 +612,7 @@ static struct dm_tree_node *_find_dm_tree_node_by_uuid(struct dm_tree *dtree, if (strcmp(suffix_position + 1, suffix)) continue; - (void) strncpy(uuid_without_suffix, uuid, sizeof(uuid_without_suffix)); + dm_strncpy(uuid_without_suffix, uuid, sizeof(uuid_without_suffix)); uuid_without_suffix[suffix_position - uuid] = '\0'; if ((node = dm_hash_lookup(dtree->uuids, uuid_without_suffix))) { diff --git a/lib/device/online.c b/lib/device/online.c index 94945b5d5..6e73668ed 100644 --- a/lib/device/online.c +++ b/lib/device/online.c @@ -432,9 +432,9 @@ int get_pvs_lookup(struct dm_list *pvs_online, const char *vgname) if (file_major || file_minor) po->devno = MKDEV(file_major, file_minor); if (file_vgname[0]) - strncpy(po->vgname, file_vgname, NAME_LEN-1); + dm_strncpy(po->vgname, file_vgname, sizeof(po->vgname)); if (file_devname[0]) - strncpy(po->devname, file_devname, NAME_LEN-1); + dm_strncpy(po->devname, file_devname, sizeof(po->devname)); log_debug("Found PV online lookup %s for VG %s on %s.", path, vgname, file_devname); dm_list_add(pvs_online, &po->list); diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index 564022359..4ed1d7467 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -558,7 +558,7 @@ static struct dm_tree_node *_find_dm_tree_node_by_uuid(struct dm_tree *dtree, const char *default_uuid_prefix; size_t default_uuid_prefix_len; const char *suffix, *suffix_position; - char uuid_without_suffix[DM_UUID_LEN]; + char uuid_without_suffix[DM_UUID_LEN + 1]; unsigned i = 0; const char **suffix_list = dtree->optional_uuid_suffixes; @@ -572,7 +572,7 @@ static struct dm_tree_node *_find_dm_tree_node_by_uuid(struct dm_tree *dtree, if (strcmp(suffix_position + 1, suffix)) continue; - (void) strncpy(uuid_without_suffix, uuid, sizeof(uuid_without_suffix)); + dm_strncpy(uuid_without_suffix, uuid, sizeof(uuid_without_suffix)); uuid_without_suffix[suffix_position - uuid] = '\0'; if ((node = dm_hash_lookup(dtree->uuids, uuid_without_suffix))) {