diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-16 13:38:54 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-16 13:38:54 -0700 |
commit | 5b860c67c3d8fcded0f88715fc69053f81c10449 (patch) | |
tree | 762ecfc92de12eed31e8b7352e97af9fe609f045 | |
parent | Fix pointer events properly (diff) | |
download | sway-5b860c67c3d8fcded0f88715fc69053f81c10449.tar.gz sway-5b860c67c3d8fcded0f88715fc69053f81c10449.tar.zst sway-5b860c67c3d8fcded0f88715fc69053f81c10449.zip |
fixed split [vh], small memory leak, unescape_strings handle \xnn
-rw-r--r-- | sway/commands.c | 4 | ||||
-rw-r--r-- | sway/container.c | 3 | ||||
-rw-r--r-- | sway/stringop.c | 67 |
3 files changed, 55 insertions, 19 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5cb661eb..842142e2 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -285,9 +285,9 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) { | |||
285 | return false; | 285 | return false; |
286 | } | 286 | } |
287 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { | 287 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { |
288 | _do_split(config, argc, argv, L_VERT); | 288 | _do_split(config, argc - 1, argv + 1, L_VERT); |
289 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { | 289 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { |
290 | _do_split(config, argc, argv, L_HORIZ); | 290 | _do_split(config, argc - 1, argv + 1, L_HORIZ); |
291 | } else { | 291 | } else { |
292 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); | 292 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); |
293 | return false; | 293 | return false; |
diff --git a/sway/container.c b/sway/container.c index 46694cbd..3158b8b0 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -31,6 +31,9 @@ static void free_swayc(swayc_t *c) { | |||
31 | } | 31 | } |
32 | remove_child(c->parent, c); | 32 | remove_child(c->parent, c); |
33 | } | 33 | } |
34 | if (c->name) { | ||
35 | free(c->name); | ||
36 | } | ||
34 | free(c); | 37 | free(c); |
35 | } | 38 | } |
36 | 39 | ||
diff --git a/sway/stringop.c b/sway/stringop.c index bbc0bcdf..1dff97bf 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -53,8 +53,9 @@ char *strip_comments(char *str) { | |||
53 | list_t *split_string(const char *str, const char *delims) { | 53 | list_t *split_string(const char *str, const char *delims) { |
54 | list_t *res = create_list(); | 54 | list_t *res = create_list(); |
55 | int i, j; | 55 | int i, j; |
56 | for (i = 0, j = 0; i < strlen(str) + 1; ++i) { | 56 | int len = strlen(str); |
57 | if (strchr(delims, str[i]) || i == strlen(str)) { | 57 | for (i = 0, j = 0; i < len + 1; ++i) { |
58 | if (strchr(delims, str[i]) || i == len) { | ||
58 | if (i - j == 0) { | 59 | if (i - j == 0) { |
59 | continue; | 60 | continue; |
60 | } | 61 | } |
@@ -63,7 +64,7 @@ list_t *split_string(const char *str, const char *delims) { | |||
63 | left[i - j] = 0; | 64 | left[i - j] = 0; |
64 | list_add(res, left); | 65 | list_add(res, left); |
65 | j = i + 1; | 66 | j = i + 1; |
66 | while (j <= strlen(str) && str[j] && strchr(delims, str[j])) { | 67 | while (j <= len && str[j] && strchr(delims, str[j])) { |
67 | j++; | 68 | j++; |
68 | i++; | 69 | i++; |
69 | } | 70 | } |
@@ -110,40 +111,72 @@ int unescape_string(char *string) { | |||
110 | for (i = 0; string[i]; ++i) { | 111 | for (i = 0; string[i]; ++i) { |
111 | if (string[i] == '\\') { | 112 | if (string[i] == '\\') { |
112 | --len; | 113 | --len; |
114 | int shift = 0; | ||
113 | switch (string[++i]) { | 115 | switch (string[++i]) { |
114 | case '0': | 116 | case '0': |
115 | string[i - 1] = '\0'; | 117 | string[i - 1] = '\0'; |
116 | memmove(string + i, string + i + 1, len - i); | 118 | shift = 1; |
117 | break; | 119 | break; |
118 | case 'a': | 120 | case 'a': |
119 | string[i - 1] = '\a'; | 121 | string[i - 1] = '\a'; |
120 | memmove(string + i, string + i + 1, len - i); | 122 | shift = 1; |
121 | break; | 123 | break; |
122 | case 'b': | 124 | case 'b': |
123 | string[i - 1] = '\b'; | 125 | string[i - 1] = '\b'; |
124 | memmove(string + i, string + i + 1, len - i); | 126 | shift = 1; |
125 | break; | 127 | break; |
126 | case 't': | 128 | case 'f': |
127 | string[i - 1] = '\t'; | 129 | string[i - 1] = '\f'; |
128 | memmove(string + i, string + i + 1, len - i); | 130 | shift = 1; |
129 | break; | 131 | break; |
130 | case 'n': | 132 | case 'n': |
131 | string[i - 1] = '\n'; | 133 | string[i - 1] = '\n'; |
132 | memmove(string + i, string + i + 1, len - i); | 134 | shift = 1; |
135 | break; | ||
136 | case 'r': | ||
137 | string[i - 1] = '\r'; | ||
138 | shift = 1; | ||
139 | break; | ||
140 | case 't': | ||
141 | string[i - 1] = '\t'; | ||
142 | shift = 1; | ||
133 | break; | 143 | break; |
134 | case 'v': | 144 | case 'v': |
135 | string[i - 1] = '\v'; | 145 | string[i - 1] = '\v'; |
136 | memmove(string + i, string + i + 1, len - i); | 146 | shift = 1; |
137 | break; | 147 | break; |
138 | case 'f': | 148 | case '\\': |
139 | string[i - 1] = '\f'; | 149 | shift = 1; |
140 | memmove(string + i, string + i + 1, len - i); | ||
141 | break; | 150 | break; |
142 | case 'r': | 151 | case '\'': |
143 | string[i - 1] = '\r'; | 152 | string[i - 1] = '\''; |
144 | memmove(string + i, string + i + 1, len - i); | 153 | shift = 1; |
154 | break; | ||
155 | case '\"': | ||
156 | string[i - 1] = '\"'; | ||
157 | shift = 1; | ||
158 | break; | ||
159 | case '?': | ||
160 | string[i - 1] = '?'; | ||
161 | shift = 1; | ||
145 | break; | 162 | break; |
163 | case 'x': | ||
164 | { | ||
165 | unsigned char c = 0; | ||
166 | shift = 1; | ||
167 | if (string[i+1] >= '0' && string[i+1] <= '9') { | ||
168 | shift = 2; | ||
169 | c = string[i+1] - '0'; | ||
170 | if (string[i+2] >= '0' && string[i+2] <= '9') { | ||
171 | shift = 3; | ||
172 | c *= 0x10; | ||
173 | c += string[i+2] - '0'; | ||
174 | } | ||
175 | } | ||
176 | string[i - 1] = c; | ||
177 | } | ||
146 | } | 178 | } |
179 | memmove(string + i, string + i + shift, len - i); | ||
147 | } | 180 | } |
148 | } | 181 | } |
149 | return len; | 182 | return len; |