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

Use memcpy and add error message

strncpy (which check each byte for \0) is not need as we always copy
the length size - so using memcpy is a bit cheaper.

Add missing log_error message for failed allocation.
This commit is contained in:
Zdenek Kabelac 2011-01-28 10:19:00 +00:00
parent a5c6acf22a
commit 7f8badfe5e

View File

@ -886,9 +886,11 @@ static char *_dup_tok(struct parser *p)
{
size_t len = p->te - p->tb;
char *str = dm_pool_alloc(p->mem, len + 1);
if (!str)
return_0;
strncpy(str, p->tb, len);
if (!str) {
log_error("Failed to duplicate token.");
return 0;
}
memcpy(str, p->tb, len);
str[len] = '\0';
return str;
}