wdvi

network DVI viewer
Log | Files | Refs

commit 5d83f81723bd0765756aeb7d1fb203ac3199a0d2
parent 56acd0fc2cc3cc01dd125cff237d2db0abd90827
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Sat, 11 Sep 2021 20:01:39 +0000

use strdup() and memcpy() instead of bcopy()

We are guaranteed to not have overlapping buffers here.

Diffstat:
Mutil.c | 21+++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/util.c b/util.c @@ -32,6 +32,8 @@ NOTE: #include <ctype.h> /* needed for memicmp() */ #include <err.h> #include <errno.h> +#include <string.h> /* strdup(), memcpy() */ +#include <strings.h> /* bcopy() */ #include <pwd.h> #include <unistd.h> @@ -77,16 +79,13 @@ xrealloc(where, size) * Allocate a new string. */ -char * -xstrdup(str) - const char *str; +char * +xstrdup(const char *str) { - size_t len; char *new; - len = strlen(str) + 1; - new = xmalloc(len); - bcopy(str, new, len); + if ((new = strdup(str)) == NULL) + err(1, "strdup"); return new; } @@ -95,15 +94,13 @@ xstrdup(str) * Allocate a new string. The second argument is the length. */ -char * -xmemdup(str, len) - const char *str; - size_t len; +char * +xmemdup(const char *str, size_t len) { char *new; new = xmalloc(len); - bcopy(str, new, len); + memcpy(new, str, len); return new; }