# HG changeset patch # User Matti Hamalainen # Date 1455530472 -7200 # Node ID 128c8cb8020540e974a16dde43e58cd8e2039b25 # Parent d58b92ef5c03ec6a1a9050e29dfe7e8837413633 Fix th_str(n)dup_trim() functions. :S diff -r d58b92ef5c03 -r 128c8cb80205 th_string.c --- a/th_string.c Mon Feb 15 10:46:45 2016 +0200 +++ b/th_string.c Mon Feb 15 12:01:12 2016 +0200 @@ -69,19 +69,19 @@ // Trim end: find last non-whitespace character if (flags & TH_TRIM_END) - for (end = len; end > start && th_isspace(src[end]); end--); + for (end = len - 1; end > start && th_isspace(src[end]); end--); else end = len; // Allocate memory for result - len = end - start; - if (len == 0) + if (src[end] == 0 || th_isspace(src[end])) return NULL; + len = end - start + 1; if ((res = th_malloc(len + 1)) == NULL) return NULL; - memcpy(res, src, len); + memcpy(res, src + start, len); res[len] = 0; return res; }