From 839dd609c42ced3f4ed5e86230ec43dcad9f2b62 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 17 Jun 2015 20:50:10 +0000 Subject: [PATCH] Use strdup in xstrdup; from Fritjof Bornebusch. --- usr.bin/diff/xmalloc.c | 8 +++----- usr.bin/rcs/xmalloc.c | 9 +++------ 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 * Copyright (c) 1995 Tatu Ylonen , 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 * Copyright (c) 1995 Tatu Ylonen , 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; } -- 2.20.1