diff options
Diffstat (limited to 'sway/stringop.c')
-rw-r--r-- | sway/stringop.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/sway/stringop.c b/sway/stringop.c index 77faf3f1..1ba54ec6 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -17,14 +17,13 @@ char *strip_whitespace(char *_str) { | |||
17 | while (*_str == ' ' || *_str == '\t') { | 17 | while (*_str == ' ' || *_str == '\t') { |
18 | _str++; | 18 | _str++; |
19 | } | 19 | } |
20 | char *str = malloc(strlen(_str) + 1); | 20 | char *str = strdup(_str); |
21 | strcpy(str, _str); | ||
22 | free(strold); | 21 | free(strold); |
23 | int i; | 22 | int i; |
24 | for (i = 0; str[i] != '\0'; ++i); | 23 | for (i = 0; str[i] != '\0'; ++i); |
25 | do { | 24 | do { |
26 | i--; | 25 | i--; |
27 | } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); | 26 | } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); |
28 | str[i + 1] = '\0'; | 27 | str[i + 1] = '\0'; |
29 | return str; | 28 | return str; |
30 | } | 29 | } |
@@ -76,9 +75,8 @@ void strip_quotes(char *str) { | |||
76 | 75 | ||
77 | list_t *split_string(const char *str, const char *delims) { | 76 | list_t *split_string(const char *str, const char *delims) { |
78 | list_t *res = create_list(); | 77 | list_t *res = create_list(); |
79 | char *copy = malloc(strlen(str) + 1); | 78 | char *copy = strdup(str); |
80 | char *token; | 79 | char *token; |
81 | strcpy(copy, str); | ||
82 | 80 | ||
83 | token = strtok(copy, delims); | 81 | token = strtok(copy, delims); |
84 | while(token) { | 82 | while(token) { |