aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/trim.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libbb/trim.c b/libbb/trim.c
index 4957d7276..94ccaf7ed 100644
--- a/libbb/trim.c
+++ b/libbb/trim.c
@@ -16,12 +16,16 @@ void trim(char *s)
size_t lws;
/* trim trailing whitespace */
- while (len && isspace(s[len-1])) --len;
+ while (len && isspace(s[len-1]))
+ --len;
/* trim leading whitespace */
if (len) {
lws = strspn(s, " \n\r\t\v");
- memmove(s, s + lws, len -= lws);
+ if (lws) {
+ len -= lws;
+ memmove(s, s + lws, len);
+ }
}
s[len] = '\0';
}