From 995ff58903898dfc60205f87b20205fbb86ab44b Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 4 Apr 2024 17:03:30 +0200 Subject: [PATCH] refactor: remove (void) from dm_strncpy usage Start to use dm_strncpy() as unchecked version within source tree. --- daemons/cmirrord/cluster.c | 2 +- lib/activate/activate.c | 2 +- lib/activate/dev_manager.c | 4 ++-- lib/commands/toolcontext.c | 2 +- lib/device/dev-cache.c | 6 +++--- lib/device/device_id.c | 8 ++++---- lib/device/online.c | 4 ++-- lib/format_text/archive.c | 2 +- lib/format_text/format-text.c | 4 ++-- lib/label/hints.c | 4 ++-- lib/log/log.c | 2 +- lib/metadata/vdo_manip.c | 2 +- lib/misc/lvm-globals.c | 6 +++--- lib/misc/sharedlib.c | 2 +- lib/uuid/uuid.c | 2 +- tools/command.c | 4 ++-- tools/lvconvert.c | 2 +- tools/vgimportclone.c | 2 +- 18 files changed, 30 insertions(+), 30 deletions(-) diff --git a/daemons/cmirrord/cluster.c b/daemons/cmirrord/cluster.c index 74712f351..4071daf79 100644 --- a/daemons/cmirrord/cluster.c +++ b/daemons/cmirrord/cluster.c @@ -1634,7 +1634,7 @@ int create_cluster_cpg(char *uuid, uint64_t luid) size = ((strlen(uuid) + 1) > CPG_MAX_NAME_LENGTH) ? CPG_MAX_NAME_LENGTH : (strlen(uuid) + 1); - (void) dm_strncpy(new->name.value, uuid, size); + dm_strncpy(new->name.value, uuid, size); new->name.length = (uint32_t)size; new->luid = luid; diff --git a/lib/activate/activate.c b/lib/activate/activate.c index e6697d429..8b2708a1d 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -502,7 +502,7 @@ int driver_version(char *version, size_t size) !dm_driver_version(_vsn, sizeof(_vsn))) return_0; - (void) dm_strncpy(version, _vsn, size); + dm_strncpy(version, _vsn, size); return 1; } diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 0795a941f..c351730eb 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -871,7 +871,7 @@ static int _info(struct cmd_context *cmd, if (strcmp(suffix_position + 1, suffix)) continue; - (void) dm_strncpy(old_style_dlid, dlid, sizeof(old_style_dlid)); + dm_strncpy(old_style_dlid, dlid, sizeof(old_style_dlid)); if (!_info_run(old_style_dlid, dminfo, read_ahead, seg_status, name_check, with_open_count, with_read_ahead, 0, 0)) @@ -2315,7 +2315,7 @@ static int _check_holder(struct dev_manager *dm, struct dm_tree *dtree, if (!memcmp(uuid, &lv->vg->id, ID_LEN) && !dm_tree_find_node_by_uuid(dtree, uuid)) { /* trims any UUID suffix (i.e. -cow) */ - (void) dm_strncpy((char*)&id, uuid, 2 * sizeof(struct id) + 1); + dm_strncpy((char*)&id, uuid, 2 * sizeof(struct id) + 1); /* If UUID is not yet in dtree, look for matching LV */ if (!(lv_det = find_lv_in_vg_by_lvid(lv->vg, &id))) { diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index 5cc936c07..d6008cfe1 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -252,7 +252,7 @@ static void _get_sysfs_dir(struct cmd_context *cmd, char *buf, size_t buf_size) return; } - (void) dm_strncpy(buf, sys_mnt, buf_size); + dm_strncpy(buf, sys_mnt, buf_size); } static uint32_t _parse_debug_fields(struct cmd_context *cmd, int cfg, const char *cfgname) diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index d97a90828..5d96db057 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -283,8 +283,8 @@ static int _compare_paths(const char *path0, const char *path1) if (slash1 < slash0) return 1; - (void) dm_strncpy(p0, path0, sizeof(p0)); - (void) dm_strncpy(p1, path1, sizeof(p1)); + dm_strncpy(p0, path0, sizeof(p0)); + dm_strncpy(p1, path1, sizeof(p1)); s0 = p0 + 1; s1 = p1 + 1; @@ -1810,7 +1810,7 @@ static int _setup_devices_file_dmeventd(struct cmd_context *cmd) return 0; cmd->enable_devices_file = 1; - (void) dm_strncpy(cmd->devices_file_path, path, sizeof(cmd->devices_file_path)); + dm_strncpy(cmd->devices_file_path, path, sizeof(cmd->devices_file_path)); return 1; } diff --git a/lib/device/device_id.c b/lib/device/device_id.c index 3cf60f9da..4a6251ab3 100644 --- a/lib/device/device_id.c +++ b/lib/device/device_id.c @@ -68,7 +68,7 @@ char *strdup_pvid(char *pvid) char *buf; if (!(buf = zalloc(ID_LEN + 1))) return_NULL; - (void)dm_strncpy(buf, pvid, ID_LEN + 1); + dm_strncpy(buf, pvid, ID_LEN + 1); return buf; } @@ -1244,7 +1244,7 @@ int device_ids_read(struct cmd_context *cmd) /* Save original for lvmdevices output. */ if (!strcmp(cmd->name, "lvmdevices")) - (void)dm_strncpy(devices_file_hostname_orig, check_id, PATH_MAX); + dm_strncpy(devices_file_hostname_orig, check_id, sizeof(devices_file_hostname_orig)); if (!cmd->device_ids_check_hostname) continue; @@ -1264,7 +1264,7 @@ int device_ids_read(struct cmd_context *cmd) /* Save original for lvmdevices output. */ if (!strcmp(cmd->name, "lvmdevices")) - (void)dm_strncpy(devices_file_product_uuid_orig, check_id, PATH_MAX); + dm_strncpy(devices_file_product_uuid_orig, check_id, sizeof(devices_file_product_uuid_orig)); if (!cmd->device_ids_check_product_uuid) continue; @@ -1487,7 +1487,7 @@ static void devices_file_backup(struct cmd_context *cmd, char *fc, char *fb, tim (de_date < low_date) || (de_date == low_date && de_time < low_time) || (de_date == low_date && de_time == low_time && de_count < low_count)) { - (void)dm_strncpy(low_name, de->d_name, sizeof(low_name)); + dm_strncpy(low_name, de->d_name, sizeof(low_name)); low_date = de_date; low_time = de_time; low_count = de_count; diff --git a/lib/device/online.c b/lib/device/online.c index cbdce2edf..94945b5d5 100644 --- a/lib/device/online.c +++ b/lib/device/online.c @@ -181,9 +181,9 @@ int get_pvs_online(struct dm_list *pvs_online, const char *vgname) if (file_major || file_minor) po->devno = MKDEV(file_major, file_minor); if (file_vgname[0]) - (void)dm_strncpy(po->vgname, file_vgname, sizeof(po->vgname)); + dm_strncpy(po->vgname, file_vgname, sizeof(po->vgname)); if (file_devname[0]) - (void)dm_strncpy(po->devname, file_devname, sizeof(po->devname)); + dm_strncpy(po->devname, file_devname, sizeof(po->devname)); log_debug("Found PV online %s for VG %s %s", path, vgname, file_devname); dm_list_add(pvs_online, &po->list); diff --git a/lib/format_text/archive.c b/lib/format_text/archive.c index 0e848cc8f..0872a2cb4 100644 --- a/lib/format_text/archive.c +++ b/lib/format_text/archive.c @@ -79,7 +79,7 @@ static int _split_vg(const char *filename, char *vgname, size_t vgsize, if (vg_len + 1 > vgsize) return 0; - (void) dm_strncpy(vgname, filename, vg_len + 1); + dm_strncpy(vgname, filename, vg_len + 1); return 1; } diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 884da9817..6bacc1d44 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -1305,8 +1305,8 @@ static int _vg_write_file(struct format_instance *fid __attribute__((unused)), if (slash == 0) strcpy(temp_dir, "."); else if (slash - tc->path_edit < PATH_MAX) { - (void) dm_strncpy(temp_dir, tc->path_edit, - (size_t) (slash - tc->path_edit + 1)); + dm_strncpy(temp_dir, tc->path_edit, + (size_t) (slash - tc->path_edit + 1)); } else { log_error("Text format failed to determine directory."); return 0; diff --git a/lib/label/hints.c b/lib/label/hints.c index d6682617a..c26410603 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -886,7 +886,7 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * if (!_dev_in_hint_hash(cmd, dev)) continue; - (void) dm_strncpy(devpath, dev_name(dev), sizeof(devpath)); + dm_strncpy(devpath, dev_name(dev), sizeof(devpath)); calc_hash = calc_crc(calc_hash, (const uint8_t *)devpath, strlen(devpath)); calc_count++; } @@ -1077,7 +1077,7 @@ int write_hint_file(struct cmd_context *cmd, int newhints) * detect when the devices on the system change, which * invalidates the existing hints. */ - (void) dm_strncpy(devpath, dev_name(dev), sizeof(devpath)); + dm_strncpy(devpath, dev_name(dev), sizeof(devpath)); hash = calc_crc(hash, (const uint8_t *)devpath, strlen(devpath)); count++; diff --git a/lib/log/log.c b/lib/log/log.c index d6a5e0f7e..d030eace7 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -391,7 +391,7 @@ void init_msg_prefix(const char *prefix) { if (prefix) /* Cut away too long prefix */ - (void) dm_strncpy(_msg_prefix, prefix, sizeof(_msg_prefix)); + dm_strncpy(_msg_prefix, prefix, sizeof(_msg_prefix)); } void init_indent(int indent) diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c index 1ee39c6d7..9930d057d 100644 --- a/lib/metadata/vdo_manip.c +++ b/lib/metadata/vdo_manip.c @@ -681,7 +681,7 @@ static int _get_memory_info(uint64_t *total_mb, uint64_t *available_mb) if ((unsigned)(++e - line) > sizeof(namebuf)) continue; // something too long - (void)dm_strncpy((char*)findme.name, line, e - line); + dm_strncpy((char*)findme.name, line, e - line); found = bsearch(&findme, mt, DM_ARRAY_SIZE(mt), sizeof(mem_table_t), _compare_mem_table_s); diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c index 06855ff13..664e9860e 100644 --- a/lib/misc/lvm-globals.c +++ b/lib/misc/lvm-globals.c @@ -164,7 +164,7 @@ void init_log_command(int log_name, int log_pid) return; else if (log_name && !log_pid) - (void) dm_strncpy(_log_command_info, _cmd_name, sizeof(_log_command_info)); + dm_strncpy(_log_command_info, _cmd_name, sizeof(_log_command_info)); else if (!log_name && log_pid) (void) dm_snprintf(_log_command_info, sizeof(_log_command_info), "%d", getpid()); @@ -212,7 +212,7 @@ void init_pv_min_size(uint64_t sectors) void set_cmd_name(const char *cmd) { - (void) dm_strncpy(_cmd_name, cmd, sizeof(_cmd_name)); + dm_strncpy(_cmd_name, cmd, sizeof(_cmd_name)); } const char *get_cmd_name(void) @@ -222,7 +222,7 @@ const char *get_cmd_name(void) void set_sysfs_dir_path(const char *path) { - (void) dm_strncpy(_sysfs_dir_path, path, sizeof(_sysfs_dir_path)); + dm_strncpy(_sysfs_dir_path, path, sizeof(_sysfs_dir_path)); } const char *log_command_info(void) diff --git a/lib/misc/sharedlib.c b/lib/misc/sharedlib.c index 544bb5fbd..7310d1485 100644 --- a/lib/misc/sharedlib.c +++ b/lib/misc/sharedlib.c @@ -37,6 +37,6 @@ void get_shared_library_path(struct cmd_context *cmd, const char *libname, !(cmd->lib_dir = find_config_tree_str(cmd, global_library_dir_CFG, NULL))) || (dm_snprintf(path, path_len, "%s/%s", cmd->lib_dir, libname) == -1) || stat(path, &info) == -1) { - (void) dm_strncpy(path, libname, path_len); + dm_strncpy(path, libname, path_len); } } diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c index 14e80f64a..4e29b889c 100644 --- a/lib/uuid/uuid.c +++ b/lib/uuid/uuid.c @@ -127,7 +127,7 @@ int id_write_format(const struct id *id, char *buffer, size_t size) assert(ID_LEN == 32); if (id->uuid[0] == '#') { - (void) dm_strncpy(buffer, (char*)id->uuid, size); + dm_strncpy(buffer, (char*)id->uuid, size); return 1; } diff --git a/tools/command.c b/tools/command.c index 121fc8ec6..91c33b408 100644 --- a/tools/command.c +++ b/tools/command.c @@ -507,7 +507,7 @@ static uint64_t _lv_to_bits(struct command *cmd, char *name) int argc; int i; - (void) dm_strncpy(buf, name, LVTYPE_LEN); + dm_strncpy(buf, name, sizeof(buf)); _split_line(buf, &argc, argv, '_'); @@ -853,7 +853,7 @@ static char *_get_oo_line(const char *str) char str2[OO_NAME_LEN]; int i; - (void) dm_strncpy(str2, str, sizeof(str2)); + dm_strncpy(str2, str, sizeof(str2)); if ((end = strchr(str2, ':'))) *end = '\0'; if ((end = strchr(str2, ','))) diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 7f25c86fb..52c7cb9c2 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -1170,7 +1170,7 @@ static int _raid_split_image_conversion(struct logical_volume *lv) if (lv_is_raid_image(lv) && (s = strstr(lv->name, "_rimage_"))) { - (void) dm_strncpy(raidlv_name, lv->name, s - lv->name); + dm_strncpy(raidlv_name, lv->name, s - lv->name); if (!(tmp_lv = find_lv(lv->vg, raidlv_name))) { log_error("Failed to find RaidLV of RAID subvolume %s.", diff --git a/tools/vgimportclone.c b/tools/vgimportclone.c index a6d055f7f..f1852cda2 100644 --- a/tools/vgimportclone.c +++ b/tools/vgimportclone.c @@ -408,7 +408,7 @@ int vgimportclone(struct cmd_context *cmd, int argc, char **argv) goto out; } if (strcmp(vgname, vp.old_vgname)) { - (void) dm_strncpy(tmp_vgname, base_vgname, NAME_LEN); + dm_strncpy(tmp_vgname, base_vgname, sizeof(tmp_vgname)); vgname_count = 0; } else { /* Needed when basename matches old name, and PV is not a duplicate