diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-16 08:09:59 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-16 08:09:59 -0400 |
commit | 76ec9422a66c4ff59dc0590d80f7f6e931fd8e1a (patch) | |
tree | 914b01d7f01ea8b90397041dce2437305453aba2 /sway/stringop.c | |
parent | 5ed999b1101e5a5830461f56977950232a6c8106 (diff) | |
parent | eefc76b39e61ce04fa8ac0e732a22c10d9c98e1f (diff) |
Merge pull request #38 from taiyu-len/master
get/set_userdata stores swayc_t *, fixed memory leak, minor changes.
Diffstat (limited to 'sway/stringop.c')
-rw-r--r-- | sway/stringop.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/sway/stringop.c b/sway/stringop.c index bbc0bcdf..450d5cd0 100644 --- a/sway/stringop.c +++ b/sway/stringop.c @@ -53,8 +53,9 @@ char *strip_comments(char *str) { list_t *split_string(const char *str, const char *delims) { list_t *res = create_list(); int i, j; - for (i = 0, j = 0; i < strlen(str) + 1; ++i) { - if (strchr(delims, str[i]) || i == strlen(str)) { + int len = strlen(str); + for (i = 0, j = 0; i < len + 1; ++i) { + if (strchr(delims, str[i]) || i == len) { if (i - j == 0) { continue; } @@ -63,7 +64,7 @@ list_t *split_string(const char *str, const char *delims) { left[i - j] = 0; list_add(res, left); j = i + 1; - while (j <= strlen(str) && str[j] && strchr(delims, str[j])) { + while (j <= len && str[j] && strchr(delims, str[j])) { j++; i++; } @@ -110,40 +111,44 @@ int unescape_string(char *string) { for (i = 0; string[i]; ++i) { if (string[i] == '\\') { --len; + int shift = 0; switch (string[++i]) { case '0': string[i - 1] = '\0'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 'a': string[i - 1] = '\a'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 'b': string[i - 1] = '\b'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 't': string[i - 1] = '\t'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 'n': string[i - 1] = '\n'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 'v': string[i - 1] = '\v'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 'f': string[i - 1] = '\f'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; case 'r': string[i - 1] = '\r'; - memmove(string + i, string + i + 1, len - i); + shift = 1; break; } + if (shift) { + memmove(string + i, string + i + shift, len - i); + } } } return len; |