# HG changeset patch # User Matti Hamalainen # Date 1583774032 -7200 # Node ID 9bbacd72df3d5346154d3029823b7ffe49a7b7d8 # Parent a04b8fe158b986153ef0d070f0597eafc0a937ed Allow src and dst to "overlap" for th_pstr_cpy(). diff -r a04b8fe158b9 -r 9bbacd72df3d th_string.c --- a/th_string.c Mon Mar 09 19:05:58 2020 +0200 +++ b/th_string.c Mon Mar 09 19:13:52 2020 +0200 @@ -528,17 +528,19 @@ int th_pstr_cpy(th_char_t **pdst, const th_char_t *src) { size_t slen; + th_char_t *tmp; if (pdst == NULL || src == NULL) return THERR_NULLPTR; - th_free(*pdst); - slen = th_strlen(src); - if ((*pdst = th_malloc((slen + 1) * sizeof(th_char_t))) == NULL) + if ((tmp = th_malloc((slen + 1) * sizeof(th_char_t))) == NULL) return THERR_MALLOC; - memcpy(*pdst, src, (slen + 1) * sizeof(th_char_t)); + memcpy(tmp, src, (slen + 1) * sizeof(th_char_t)); + + th_free(*pdst); + *pdst = tmp; return THERR_OK; }