summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/diff/xmalloc.c8
-rw-r--r--usr.bin/rcs/xmalloc.c9
2 files changed, 6 insertions, 11 deletions
diff --git a/usr.bin/diff/xmalloc.c b/usr.bin/diff/xmalloc.c
index 2eccb0fd63a..5d1483eaff7 100644
--- a/usr.bin/diff/xmalloc.c
+++ b/usr.bin/diff/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.6 2015/04/29 04:00:25 deraadt Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.7 2015/06/17 20:50:10 nicm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -73,12 +73,10 @@ xfree(void *ptr)
char *
xstrdup(const char *str)
{
- size_t len;
char *cp;
- len = strlen(str) + 1;
- cp = xmalloc(len);
- strlcpy(cp, str, len);
+ if ((cp = strdup(str)) == NULL)
+ err(1, "xstrdup");
return cp;
}
diff --git a/usr.bin/rcs/xmalloc.c b/usr.bin/rcs/xmalloc.c
index 00f4a464c74..2aab4f89f14 100644
--- a/usr.bin/rcs/xmalloc.c
+++ b/usr.bin/rcs/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.9 2015/06/13 20:15:21 nicm Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.10 2015/06/17 20:50:10 nicm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -68,13 +68,10 @@ xreallocarray(void *ptr, size_t nmemb, size_t size)
char *
xstrdup(const char *str)
{
- size_t len;
char *cp;
- len = strlen(str) + 1;
- cp = xmalloc(len);
- if (strlcpy(cp, str, len) >= len)
- errx(1, "xstrdup: string truncated");
+ if ((cp = strdup(str)) == NULL)
+ err(1, "xstrdup");
return cp;
}