# HG changeset patch # User Matti Hamalainen # Date 1587947628 -10800 # Node ID ec6a3790a91b312495a32e672fbbf68d211175b1 # Parent 3ea040bb0dcab6ab5bb76949b23a2991122c8c65 Do not use th_strlen() in th_strndup(), as the string might not have a terminating NUL before the n'th character. diff -r 3ea040bb0dca -r ec6a3790a91b th_string.c --- 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;