aboutsummaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/str.c b/src/str.c
index 22aebac..011da99 100644
--- a/src/str.c
+++ b/src/str.c
@@ -65,12 +65,17 @@ void destroy_str_list(char **list) {
char *str_strip(char *str) {
if (str == NULL) return NULL;
int len = strlen(str);
+ if (len == 0) {
+ char* ret = malloc(1);
+ ret[0] = '\0';
+ return ret;
+ }
char *begin = str;
char *end = str + len - 1;
while (isspace(*begin) && begin < end) {
begin++;
}
- while (isspace(*end) && end >= begin) {
+ while (end >= begin && isspace(*end)) {
end--;
}
len = end - begin + 1;