From 8440981845765c916febec9f42dbaa3315dceb0e Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 28 Jan 2011 10:19:00 +0000 Subject: [PATCH] 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. --- lib/config/config.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/config/config.c b/lib/config/config.c index 72908f2a3..ffa9fd6d4 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -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; } -- 2.43.5