diff --git a/Src/string.c b/Src/string.c
index 04e7446..f78fcba 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -28,16 +28,33 @@
 
 #include "zsh.mdh"
 
+#define copymemory_maybestring(dest,src,l,type) do      \
+            {                                           \
+                if( l < 8 ) {                           \
+                    type *d_;                           \
+                    const type *s_;                     \
+                    d_ = dest;                          \
+                    s_ = src;                           \
+                    while( (*d_++ = *s_++) ) {}         \
+                } else {                                \
+                    memcpy(dest, src, l*sizeof(type));  \
+                }                                       \
+            } while(0);
+
 /**/
 mod_export char *
 dupstring(const char *s)
 {
     char *t;
+    size_t lenw0;
 
     if (!s)
 	return NULL;
-    t = (char *) zhalloc(strlen((char *)s) + 1);
-    strcpy(t, s);
+
+    lenw0 = 1 + strlen((char *)s);
+    t = (char *) zhalloc(lenw0 * sizeof(char));
+    copymemory_maybestring(t, s, lenw0, char);
+
     return t;
 }
 
@@ -46,11 +63,15 @@ mod_export char *
 ztrdup(const char *s)
 {
     char *t;
+    size_t lenw0;
 
     if (!s)
 	return NULL;
-    t = (char *)zalloc(strlen((char *)s) + 1);
-    strcpy(t, s);
+
+    lenw0= 1 + strlen((char *)s);
+    t = (char *)zalloc(lenw0 * sizeof(char));
+    copymemory_maybestring(t, s, lenw0, char);
+
     return t;
 }
 
@@ -61,11 +82,15 @@ mod_export wchar_t *
 wcs_ztrdup(const wchar_t *s)
 {
     wchar_t *t;
+    size_t lenw0;
 
     if (!s)
 	return NULL;
-    t = (wchar_t *)zalloc(sizeof(wchar_t) * (wcslen((wchar_t *)s) + 1));
-    wcscpy(t, s);
+
+    lenw0 = 1 + wcslen((wchar_t *)s);
+    t = (wchar_t *)zalloc(lenw0 * sizeof(wchar_t));
+    copymemory_maybestring(t, s, lenw0, wchar_t);
+
     return t;
 }
 /**/
@@ -80,13 +105,14 @@ tricat(char const *s1, char const *s2, char const *s3)
 {
     /* This version always uses permanently-allocated space. */
     char *ptr;
-    size_t l1 = strlen(s1);
-    size_t l2 = strlen(s2);
-
-    ptr = (char *)zalloc(l1 + l2 + strlen(s3) + 1);
-    strcpy(ptr, s1);
-    strcpy(ptr + l1, s2);
-    strcpy(ptr + l1 + l2, s3);
+    size_t l1w0 = 1 + strlen(s1);
+    size_t l2w0 = 1 + strlen(s2);
+    size_t l3w0 = 1 + strlen(s3);
+
+    ptr = (char *)zalloc((l1w0 + l2w0 + l3w0 - 2) * sizeof(char));
+    copymemory_maybestring(ptr, s1, l1w0, char);
+    copymemory_maybestring(ptr + l1w0 - 1, s2, l2w0, char);
+    copymemory_maybestring(ptr + l1w0 - 1 + l2w0 - 1, s3, l3w0, char);
     return ptr;
 }
 
@@ -95,13 +121,14 @@ mod_export char *
 zhtricat(char const *s1, char const *s2, char const *s3)
 {
     char *ptr;
-    size_t l1 = strlen(s1);
-    size_t l2 = strlen(s2);
-
-    ptr = (char *)zhalloc(l1 + l2 + strlen(s3) + 1);
-    strcpy(ptr, s1);
-    strcpy(ptr + l1, s2);
-    strcpy(ptr + l1 + l2, s3);
+    size_t l1w0 = 1 + strlen(s1);
+    size_t l2w0 = 1 + strlen(s2);
+    size_t l3w0 = 1 + strlen(s3);
+
+    ptr = (char *)zhalloc((l1w0 + l2w0 + l3w0 - 2) * sizeof(char));
+    copymemory_maybestring(ptr, s1, l1w0, char);
+    copymemory_maybestring(ptr + l1w0 - 1, s2, l2w0, char);
+    copymemory_maybestring(ptr + l1w0 - 1 + l2w0 - 1, s3, l3w0, char);
     return ptr;
 }
 
@@ -113,11 +140,12 @@ dyncat(const char *s1, const char *s2)
 {
     /* This version always uses space from the current heap. */
     char *ptr;
-    size_t l1 = strlen(s1);
+    size_t l1w0 = 1 + strlen(s1);
+    size_t l2w0 = 1 + strlen(s2);
 
-    ptr = (char *)zhalloc(l1 + strlen(s2) + 1);
-    strcpy(ptr, s1);
-    strcpy(ptr + l1, s2);
+    ptr = (char *)zhalloc(l1w0 + l2w0 - 1);
+    copymemory_maybestring(ptr, s1, l1w0, char);
+    copymemory_maybestring(ptr + l1w0 - 1, s2, l2w0, char);
     return ptr;
 }
 
@@ -127,11 +155,12 @@ bicat(const char *s1, const char *s2)
 {
     /* This version always uses permanently-allocated space. */
     char *ptr;
-    size_t l1 = strlen(s1);
+    size_t l1w0 = 1 + strlen(s1);
+    size_t l2w0 = 1 + strlen(s2);
 
-    ptr = (char *)zalloc(l1 + strlen(s2) + 1);
-    strcpy(ptr, s1);
-    strcpy(ptr + l1, s2);
+    ptr = (char *)zalloc(l1w0 + l2w0 - 1);
+    copymemory_maybestring(ptr, s1, l1w0, char);
+    copymemory_maybestring(ptr + l1w0 - 1, s2, l2w0, char);
     return ptr;
 }
 
