diff options
author | Rob Landley <rob@landley.net> | 2022-03-22 14:25:46 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2022-03-22 14:25:46 -0500 |
commit | 1ba8a12c4da4439a310864c278e156bce0774537 (patch) | |
tree | 5f6d6281808019486658f810fc69bb3befd5467a | |
parent | 3f7ea911d886343d3f388371f6dad7572428625a (diff) | |
download | toybox-1ba8a12c4da4439a310864c278e156bce0774537.tar.gz |
Avoid redundant strlen() inside libc.
-rw-r--r-- | lib/xwrap.c | 7 |
1 files changed, 6 insertions, 1 deletions
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) |