changeset 522:b4884e59fdd3

Simplify th_strdup().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 26 Dec 2019 22:26:19 +0200
parents 77495c646208
children 9acbbfea68a9
files th_string.c
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Thu Dec 26 13:34:19 2019 +0200
+++ b/th_string.c	Thu Dec 26 22:26:19 2019 +0200
@@ -14,13 +14,16 @@
 char *th_strdup(const char *src)
 {
     char *res;
+    size_t len;
+
     if (src == NULL)
         return NULL;
 
-    if ((res = th_malloc(strlen(src) + 1)) == NULL)
+    len = strlen(src);
+    if ((res = th_malloc(len + 1)) == NULL)
         return NULL;
 
-    strcpy(res, src);
+    memcpy(res, src, len + 1);
     return res;
 }