aboutsummaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/str.c b/src/str.c
index dbf0c42..605bbee 100644
--- a/src/str.c
+++ b/src/str.c
@@ -453,12 +453,18 @@ char *lstrip(char *sptr) {
* @return truncated string
*/
char *strip(char *sptr) {
- size_t len = strlen(sptr) - 1;
- if (len < 1 && isblank(*sptr)) {
+ size_t len = strlen(sptr);
+ if (len == 0) {
+ return sptr;
+ }
+ else if (len == 1) {
*sptr = '\0';
return sptr;
}
- for (size_t i = len; ; i--) {
+ for (size_t i = len; i != 0; --i) {
+ if (sptr[i] == '\0') {
+ continue;
+ }
if (isspace(sptr[i]) || isblank(sptr[i])) {
sptr[i] = '\0';
}