From 1ba8a12c4da4439a310864c278e156bce0774537 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 22 Mar 2022 14:25:46 -0500 Subject: [PATCH] Avoid redundant strlen() inside libc. --- lib/xwrap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/xwrap.c b/lib/xwrap.c index f16ebe03..65e9f4fe 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -104,7 +104,12 @@ char *xstrndup(char *s, size_t n) // Die unless we can allocate a copy of this string. char *xstrdup(char *s) { - return xstrndup(s, strlen(s)); + long len = strlen(s); + char *c = xmalloc(++len); + + memcpy(c, s, len); + + return c; } void *xmemdup(void *s, long len) -- 2.39.2