lib: strncpy -> strlcpy | memcpy

strncpy is a byte copy function not a string copy function

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2019-02-26 20:25:24 +00:00
parent 5c84f23817
commit aab9a0a0cb
3 changed files with 5 additions and 5 deletions

View File

@ -62,7 +62,7 @@ const char *event_counter_format(const struct event_counter *counter)
|| strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %T %z",
last_change)
== 0) {
strncpy(timebuf, "???", sizeof(timebuf));
strlcpy(timebuf, "???", sizeof(timebuf));
}
snprintf(rv, sizeof(rv), "%5llu last: %s", counter->count,

View File

@ -866,7 +866,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p)
return ret;
} else {
cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1);
strncpy(cp, str, pnt - str);
memcpy(cp, str, pnt - str);
*(cp + (pnt - str)) = '\0';
ret = inet_aton(cp, &p->prefix);
XFREE(MTYPE_TMP, cp);
@ -913,7 +913,7 @@ int str2prefix_eth(const char *str, struct prefix_eth *p)
}
cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1);
strncpy(cp, str, pnt - str);
memcpy(cp, str, pnt - str);
*(cp + (pnt - str)) = '\0';
str_addr = cp;
@ -1030,7 +1030,7 @@ int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p)
int plen;
cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1);
strncpy(cp, str, pnt - str);
memcpy(cp, str, pnt - str);
*(cp + (pnt - str)) = '\0';
ret = inet_pton(AF_INET6, cp, &p->prefix);
XFREE(MTYPE_TMP, cp);

View File

@ -511,7 +511,7 @@ static void str_replace(char *o_string, const char *s_string,
if (!ch)
return;
strncpy(buffer, o_string, ch - o_string);
memcpy(buffer, o_string, ch - o_string);
buffer[ch - o_string] = 0;
sprintf(buffer + (ch - o_string), "%s%s", r_string,