aboutsummaryrefslogtreecommitdiff
path: root/libbb/trim.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/trim.c')
-rw-r--r--libbb/trim.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/libbb/trim.c b/libbb/trim.c
index ea20ff370..df00b846e 100644
--- a/libbb/trim.c
+++ b/libbb/trim.c
@@ -13,7 +13,6 @@
13void FAST_FUNC trim(char *s) 13void FAST_FUNC trim(char *s)
14{ 14{
15 size_t len = strlen(s); 15 size_t len = strlen(s);
16 size_t lws;
17 16
18 /* trim trailing whitespace */ 17 /* trim trailing whitespace */
19 while (len && isspace(s[len-1])) 18 while (len && isspace(s[len-1]))
@@ -21,10 +20,10 @@ void FAST_FUNC trim(char *s)
21 20
22 /* trim leading whitespace */ 21 /* trim leading whitespace */
23 if (len) { 22 if (len) {
24 lws = strspn(s, " \n\r\t\v"); 23 char *nws = skip_whitespace(s);
25 if (lws) { 24 if ((nws - s) != 0) {
26 len -= lws; 25 len -= (nws - s);
27 memmove(s, s + lws, len); 26 memmove(s, nws, len);
28 } 27 }
29 } 28 }
30 s[len] = '\0'; 29 s[len] = '\0';