From: Michael Stapelberg Date: Fri, 26 Nov 2010 10:25:02 +0000 (+0100) Subject: Bugfix: Correctly count variables when parsing the configfile (Thanks dbp) X-Git-Tag: 4.0~26 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a1c861e6e0d8171f9a8d7f56ad3ce35152c46420;p=i3%2Fi3 Bugfix: Correctly count variables when parsing the configfile (Thanks dbp) --- diff --git a/src/cfgparse.y b/src/cfgparse.y index 7818c136..7bbf66bf 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -119,14 +119,21 @@ void parse_file(const char *f) { * how much extra bytes it requires when replaced. */ struct Variable *current, *nearest; int extra_bytes = 0; + /* We need to copy the buffer because we need to invalidate the + * variables (otherwise we will count them twice, which is bad when + * 'extra' is negative) */ + char *bufcopy = sstrdup(buf); SLIST_FOREACH(current, &variables, variables) { int extra = (strlen(current->value) - strlen(current->key)); char *next; for (next = buf; (next = strcasestr(buf + (next - buf), current->key)) != NULL; - next += strlen(current->key)) + next += strlen(current->key)) { + *next = '_'; extra_bytes += extra; + } } + FREE(bufcopy); /* Then, allocate a new buffer and copy the file over to the new one, * but replace occurences of our variables */