]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Correctly count variables when parsing the configfile (Thanks dbp)
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 26 Nov 2010 10:25:02 +0000 (11:25 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 26 Nov 2010 10:25:51 +0000 (11:25 +0100)
src/cfgparse.y

index 5de08bde2beb6cc6af452001315736e4ad1117bf..260e30132fcbb12e2dc60ad493c7647fc835a230 100644 (file)
@@ -106,14 +106,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 */