aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/config.c b/config.c
index 56acb0cf..939a8c7e 100644
--- a/config.c
+++ b/config.c
@@ -398,6 +398,25 @@ str_to_double(const char *s, double *res)
}
static bool
+str_to_wchars(const char *s, wchar_t **res, struct config *conf,
+ const char *path, int lineno,
+ const char *section, const char *key)
+{
+ *res = NULL;
+
+ size_t chars = mbstowcs(NULL, s, 0);
+ if (chars == (size_t)-1) {
+ LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid string: %s",
+ path, lineno, section, key, s);
+ return false;
+ }
+
+ *res = xmalloc((chars + 1) * sizeof(wchar_t));
+ mbstowcs(*res, s, chars + 1);
+ return true;
+}
+
+static bool
str_to_color(const char *s, uint32_t *color, bool allow_alpha,
struct config *conf, const char *path, int lineno,
const char *section, const char *key)
@@ -712,18 +731,15 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "word-delimiters") == 0) {
- size_t chars = mbstowcs(NULL, value, 0);
- if (chars == (size_t)-1) {
- LOG_AND_NOTIFY_ERR(
- "%s:%d: [default]: word-delimiters: invalid string: %s",
- path, lineno, value);
+ wchar_t *word_delimiters;
+ if (!str_to_wchars(value, &word_delimiters, conf, path, lineno,
+ "default", "word-delimiters"))
+ {
return false;
}
-
free(conf->word_delimiters);
+ conf->word_delimiters = word_delimiters;
- conf->word_delimiters = xmalloc((chars + 1) * sizeof(wchar_t));
- mbstowcs(conf->word_delimiters, value, chars + 1);
}
else if (strcmp(key, "notify") == 0) {