Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=65eb29503b7cfe0f509c5b... Commit: 65eb29503b7cfe0f509c5b4d6146dd7961d1f8ba Parent: 93dfb5dd3eb1b6f96f227cba961abfaa00d2f300 Author: Zdenek Kabelac zkabelac@redhat.com AuthorDate: Sat Dec 1 00:35:41 2018 +0100 Committer: Zdenek Kabelac zkabelac@redhat.com CommitterDate: Sat Dec 1 01:04:27 2018 +0100
libdm: optimize dm_pool_strndup
--- libdm/mm/pool.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/libdm/mm/pool.c b/libdm/mm/pool.c index a8fe732..26f43a7 100644 --- a/libdm/mm/pool.c +++ b/libdm/mm/pool.c @@ -59,11 +59,13 @@ char *dm_pool_strdup(struct dm_pool *p, const char *str)
char *dm_pool_strndup(struct dm_pool *p, const char *str, size_t n) { + size_t slen = strlen(str); + size_t len = (slen < n) ? slen : n; char *ret = dm_pool_alloc(p, n + 1);
if (ret) { - strncpy(ret, str, n); - ret[n] = '\0'; + ret[len] = '\0'; + memcpy(ret, str, len); }
return ret;
lvm2-commits@lists.fedorahosted.org