diff --git a/config.c b/config.c index c668fd4..99d87fc 100644 --- a/config.c +++ b/config.c @@ -734,17 +734,18 @@ int load_config_file(struct mako_config *config, char *config_arg) { wl_container_of(config->criteria.next, criteria, link); size_t n = 0; - while (getline(&line, &n, f) > 0) { + ssize_t len = 0; + while ((len = getline(&line, &n, f)) != -1) { ++lineno; if (line[0] == '\0' || line[0] == '\n' || line[0] == '#') { continue; } - if (line[strlen(line) - 1] == '\n') { - line[strlen(line) - 1] = '\0'; + if (line[len - 1] == '\n') { + line[--len] = '\0'; } - if (line[0] == '[' && line[strlen(line) - 1] == ']') { + if (line[0] == '[' && line[len - 1] == ']') { // Since we hit the end of the previous criteria section, validate // that it doesn't break any rules before moving on. if (criteria != NULL && !validate_criteria(criteria)) { @@ -755,7 +756,7 @@ int load_config_file(struct mako_config *config, char *config_arg) { } free(section); - section = strndup(line + 1, strlen(line) - 2); + section = strndup(line + 1, len - 2); criteria = create_criteria(config); if (!parse_criteria(section, criteria)) { fprintf(stderr, "[%s:%d] Invalid criteria definition\n", base, @@ -773,6 +774,13 @@ int load_config_file(struct mako_config *config, char *config_arg) { break; } + // Strip end-of-line whitespace + char *whitespace = &line[len - 1]; + while (whitespace[0] == ' ') { + --whitespace; + } + whitespace[1] = '\0'; + bool valid_option = false; eq[0] = '\0'; @@ -784,6 +792,7 @@ int load_config_file(struct mako_config *config, char *config_arg) { if (!valid_option) { + eq[0] = '='; fprintf(stderr, "[%s:%d] Failed to parse option '%s'\n", base, lineno, line); ret = -1;