mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 08:43:19 -04:00
libkern: strdup.c, strndup.c: Prefer memcpy() over bcopy()
The newly allocated memory can not overlap with the string if the string is properly null-terminated or the maxlen is a valid lengh, i.e no out of bounds reads. Prefer memcpy() over memmove(), aka bcopy(), for slight performance gain. No functional change intended. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D49026
This commit is contained in:
parent
408394185f
commit
90a3b6a7a4
2 changed files with 2 additions and 2 deletions
|
|
@ -46,7 +46,7 @@ strdup_flags(const char *string, struct malloc_type *type, int flags)
|
|||
copy = malloc(len, type, flags);
|
||||
if (copy == NULL)
|
||||
return (NULL);
|
||||
bcopy(string, copy, len);
|
||||
memcpy(copy, string, len);
|
||||
return (copy);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ strndup(const char *string, size_t maxlen, struct malloc_type *type)
|
|||
|
||||
len = strnlen(string, maxlen) + 1;
|
||||
copy = malloc(len, type, M_WAITOK);
|
||||
bcopy(string, copy, len);
|
||||
memcpy(copy, string, len);
|
||||
copy[len - 1] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue