changeset 714:ec6a3790a91b

Do not use th_strlen() in th_strndup(), as the string might not have a terminating NUL before the n'th character.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Apr 2020 03:33:48 +0300
parents 3ea040bb0dca
children 6f627f4f11db
files th_string.c
diffstat 1 files changed, 1 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Mon Apr 27 01:35:39 2020 +0300
+++ b/th_string.c	Mon Apr 27 03:33:48 2020 +0300
@@ -87,9 +87,7 @@
     if (src == NULL)
         return NULL;
 
-    len = th_strlen(src);
-    if (len > n)
-        len = n;
+    for (len = 0; len < n && src[len]; len++);
 
     if ((res = th_malloc((len + 1) * sizeof(th_char_t))) == NULL)
         return NULL;