aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/trim.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libbb/trim.c b/libbb/trim.c
index 16cb4fbb0..e47fec74e 100644
--- a/libbb/trim.c
+++ b/libbb/trim.c
@@ -10,9 +10,10 @@
#include "libbb.h"
-void FAST_FUNC trim(char *s)
+char* FAST_FUNC trim(char *s)
{
size_t len = strlen(s);
+ size_t old = len;
/* trim trailing whitespace */
while (len && isspace(s[len-1]))
@@ -26,5 +27,12 @@ void FAST_FUNC trim(char *s)
memmove(s, nws, len);
}
}
- s[len] = '\0';
+
+ s += len;
+ /* If it was a "const char*" which does not need trimming,
+ * avoid superfluous store */
+ if (old != len)
+ *s = '\0';
+
+ return s;
}