summaryrefslogtreecommitdiff
path: root/lib/activate
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2021-08-03 15:32:33 -0500
committerDavid Teigland <teigland@redhat.com>2021-08-16 11:31:15 -0500
commit96b777167c63eaf2e8ef1a2e7a92dc6c66cbcd6a (patch)
tree119866852962485b85c1507ff47addd6e931aaae /lib/activate
parent0d572d14ad14afad43a8a3f5fe033ed3996c05c6 (diff)
downloadlvm2-96b777167c63eaf2e8ef1a2e7a92dc6c66cbcd6a.tar.gz
cov: clean up pvid and vgid usage
pvid and vgid are sometimes a null-terminated string, and other times a 'struct id', and the two types were often cast between each other. When a struct id was cast to a char pointer, the resulting string would not necessarily be null terminated. Casting a null-terminated string id to a struct id is fine, but is still avoided when possible. A struct id is: int8_t uuid[ID_LEN] A string id is: char pvid[ID_LEN + 1] A convention is introduced to help distinguish them: - variables and struct fields named "pvid" or "vgid" should be null-terminated strings. - variables and struct fields named "pv_id" or "vg_id" should be struct id's. - examples: char pvid[ID_LEN + 1]; char vgid[ID_LEN + 1]; struct id pv_id; struct id vg_id; Function names also attempt to follow this convention. Avoid casting between the two types as much as possible, with limited exceptions when known to be safe and clearly commented. Avoid using variations of strcpy and strcmp, and instead use memcpy/memcmp with ID_LEN (with similar limited exceptions possible.)
Diffstat (limited to 'lib/activate')
-rw-r--r--lib/activate/dev_manager.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index c4a673901..2ada9b525 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -2118,7 +2118,7 @@ static int _check_holder(struct dev_manager *dm, struct dm_tree *dtree,
if (!strncmp(default_uuid_prefix, uuid, default_uuid_prefix_len))
uuid += default_uuid_prefix_len;
- if (!strncmp(uuid, (char*)&lv->vg->id, sizeof(lv->vg->id)) &&
+ 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);