X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcommands_parser.c;h=ffe416f04dd1c3659ff0aae5687f02269ee63700;hb=1f79c44cde1fcf746b36443a10d64524702b8bc6;hp=f325a048afc6ebf6859ee81347fafd7c8dc4de28;hpb=ea2552e8524fd2064d4ed26d89ddeba49af3d717;p=i3%2Fi3 diff --git a/src/commands_parser.c b/src/commands_parser.c index f325a048..ffe416f0 100644 --- a/src/commands_parser.c +++ b/src/commands_parser.c @@ -4,7 +4,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * * commands_parser.c: hand-written parser to parse commands (commands are what * you bind on keys and what you can send to i3 using the IPC interface, like @@ -148,9 +148,9 @@ static TAILQ_HEAD(criteria_head, criterion) criteria = */ static void push_criterion(void *unused_criteria, const char *type, const char *value) { - struct criterion *criterion = malloc(sizeof(struct criterion)); - criterion->type = strdup(type); - criterion->value = strdup(value); + struct criterion *criterion = smalloc(sizeof(struct criterion)); + criterion->type = sstrdup(type); + criterion->value = sstrdup(value); TAILQ_INSERT_TAIL(&criteria, criterion, criteria); } @@ -216,8 +216,9 @@ char *parse_string(const char **walk, bool as_word) { if (**walk == '"') { beginning++; (*walk)++; - while (**walk != '\0' && (**walk != '"' || *(*walk - 1) == '\\')) - (*walk)++; + for (; **walk != '\0' && **walk != '"'; (*walk)++) + if (**walk == '\\' && *(*walk + 1) != '\0') + (*walk)++; } else { if (!as_word) { /* For a string (starting with 's'), the delimiters are @@ -242,16 +243,16 @@ char *parse_string(const char **walk, bool as_word) { if (*walk == beginning) return NULL; - char *str = scalloc(*walk - beginning + 1); + char *str = scalloc(*walk - beginning + 1, 1); /* We copy manually to handle escaping of characters. */ int inpos, outpos; for (inpos = 0, outpos = 0; inpos < (*walk - beginning); inpos++, outpos++) { - /* We only handle escaped double quotes to not break - * backwards compatibility with people using \w in - * regular expressions etc. */ - if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"') + /* We only handle escaped double quotes and backslashes to not break + * backwards compatibility with people using \w in regular expressions + * etc. */ + if (beginning[inpos] == '\\' && (beginning[inpos + 1] == '"' || beginning[inpos + 1] == '\\')) inpos++; str[outpos] = beginning[inpos]; } @@ -269,7 +270,7 @@ char *parse_string(const char **walk, bool as_word) { CommandResult *parse_command(const char *input, yajl_gen gen) { DLOG("COMMAND: *%s*\n", input); state = INITIAL; - CommandResult *result = scalloc(sizeof(CommandResult)); + CommandResult *result = scalloc(1, sizeof(CommandResult)); /* A YAJL JSON generator used for formatting replies. */ command_output.json_gen = gen;