aboutsummaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-06 12:58:14 +0800
committerMistivia <i@mistivia.com>2025-06-06 12:58:14 +0800
commit1fad3a10fe4743d69342de294cc65bfe66e32bc9 (patch)
treed91be066e44fe7af1eeece0f1b081463bc64dfc7 /src/str.c
parent4779050053cb5f73b54ff936c6393e82ffe5605c (diff)
fix leak and hashtable bug
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;