From ae9f27da1337ac2f78eb2f5c0c198614ef9173dd Mon Sep 17 00:00:00 2001 From: Bernd Busse Date: Thu, 22 Feb 2018 19:53:47 +0100 Subject: [PATCH] Fix config file parsing --- src/common.h | 17 ++--------------- src/compton.c | 7 +++---- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/common.h b/src/common.h index 701bd784..8daa6584 100644 --- a/src/common.h +++ b/src/common.h @@ -1707,20 +1707,7 @@ parse_blur_method(session_t *ps, const char *str) { * Parse a blur_strength option argument. */ static inline bool -parse_blur_strength(session_t *ps, const char *str) { - const char *endptr = NULL; - long level = strtol(str, (char **) &endptr, 0); - if (!endptr || endptr == str) { - printf_errf("(\"%s\"): Invalid number.", str); - return false; - } - while (isspace(*endptr)) - ++endptr; - if (*endptr) { - printf_errf("(\"%s\"): Trailing characters.", str); - return false; - } - +parse_blur_strength(session_t *ps, const int level) { switch (level) { case 1: ps->o.blur_strength_iterations = 1; @@ -1783,7 +1770,7 @@ parse_blur_strength(session_t *ps, const char *str) { ps->o.blur_strength_offset = 8.0; break; default: - printf_errf("(\"%s\"): Invalid blur_strength argument. Needs to be a number between 1 and 15.", str); + printf_errf("(\"%d\"): Invalid blur_strength argument. Needs to be a number between 1 and 15.", level); return false; } diff --git a/src/compton.c b/src/compton.c index 7c847911..83226fc9 100644 --- a/src/compton.c +++ b/src/compton.c @@ -5645,9 +5645,8 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) { && !parse_conv_kern_lst(ps, sval, ps->o.blur_kerns, MAX_BLUR_PASS)) exit(1); // --blur-strength - //lcfg_lookup_int(&cfg, "blur-strength", &ps->o.blur_strength); - if (config_lookup_string(&cfg, "blur-strength", &sval) - && !parse_blur_strength(ps, sval)) + if (lcfg_lookup_int(&cfg, "blur-strength", &ival) + && !parse_blur_strength(ps, ival)) exit(1); // --resize-damage lcfg_lookup_int(&cfg, "resize-damage", &ps->o.resize_damage); @@ -6063,7 +6062,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { break; case 322: // --blur-strength - if (!parse_blur_strength(ps, optarg)) + if (!parse_blur_strength(ps, strtol(optarg, NULL, 0))) exit(1); break; P_CASEBOOL(731, reredir_on_root_change);