1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cov: replace strcpy with memcpy

When we know the size we can avoid using strcpy.
This commit is contained in:
Zdenek Kabelac 2024-04-09 11:40:20 +02:00
parent 22a0cfdc05
commit 8545621d39
3 changed files with 8 additions and 6 deletions

View File

@ -1380,6 +1380,7 @@ int dev_cache_add_dir(const char *path)
{
struct dir_list *dl;
struct stat st;
size_t len;
if (stat(path, &st)) {
log_warn("Ignoring %s: %s.", path, strerror(errno));
@ -1392,12 +1393,13 @@ int dev_cache_add_dir(const char *path)
return 1;
}
if (!(dl = _zalloc(sizeof(*dl) + strlen(path) + 1))) {
len = strlen(path);
if (!(dl = _zalloc(sizeof(*dl) + len + 1))) {
log_error("dir_list allocation failed");
return 0;
}
strcpy(dl->dir, path);
memcpy(dl->dir, path, len + 1);
dm_list_add(&_cache.dirs, &dl->list);
return 1;
}

View File

@ -55,15 +55,15 @@ static struct labeller_i *_alloc_li(const char *name, struct labeller *l)
struct labeller_i *li;
size_t len;
len = sizeof(*li) + strlen(name) + 1;
len = strlen(name);
if (!(li = malloc(len))) {
if (!(li = malloc(sizeof(*li) + len + 1))) {
log_error("Couldn't allocate memory for labeller list object.");
return NULL;
}
li->l = l;
strcpy(li->name, name);
memcpy(li->name, name, len + 1);
return li;
}

View File

@ -383,7 +383,7 @@ int buffer_append(struct buffer *buf, const char *string)
!buffer_realloc(buf, len + 1))
return 0;
strcpy(buf->mem + buf->used, string);
memcpy(buf->mem + buf->used, string, len + 1);
buf->used += len;
return 1;
}