mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +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:
parent
5ba08f195a
commit
8440981845
@ -886,9 +886,11 @@ static char *_dup_tok(struct parser *p)
|
|||||||
{
|
{
|
||||||
size_t len = p->te - p->tb;
|
size_t len = p->te - p->tb;
|
||||||
char *str = dm_pool_alloc(p->mem, len + 1);
|
char *str = dm_pool_alloc(p->mem, len + 1);
|
||||||
if (!str)
|
if (!str) {
|
||||||
return_0;
|
log_error("Failed to duplicate token.");
|
||||||
strncpy(str, p->tb, len);
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(str, p->tb, len);
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user