]> sourceware.org Git - lvm2.git/commitdiff
cov: replace strcpy with memcpy
authorZdenek Kabelac <zkabelac@redhat.com>
Tue, 9 Apr 2024 09:40:20 +0000 (11:40 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Tue, 9 Apr 2024 22:03:09 +0000 (00:03 +0200)
When we know the size we can avoid using strcpy.

lib/device/dev-cache.c
lib/label/label.c
libdaemon/client/config-util.c

index fadcaca341847c64f56f87c6167c79c3863aabcc..e6f4ec8863ce28b28555cd71cc23e2ffebc959c0 100644 (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;
 }
index 38b5cf79976bde5fe41b34d8711fc79667c6555b..500a43364594e2550418d365f31dd1532ad6b02e 100644 (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;
 }
index 3f27f31495654596ed45d8223ecbb3d988e86dd0..b0813f17626b4aee9b32c0f7b84333c4d4b956c8 100644 (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;
 }
This page took 0.044876 seconds and 5 git commands to generate.