mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-08 08:20:59 -04:00
config: value_to_wchars(): free the target variable
This commit is contained in:
parent
2f0ab1da89
commit
73c5754f5d
1 changed files with 11 additions and 34 deletions
45
config.c
45
config.c
|
|
@ -579,14 +579,13 @@ value_to_str(struct context *ctx, char **res)
|
||||||
static bool NOINLINE
|
static bool NOINLINE
|
||||||
value_to_wchars(struct context *ctx, wchar_t **res)
|
value_to_wchars(struct context *ctx, wchar_t **res)
|
||||||
{
|
{
|
||||||
*res = NULL;
|
|
||||||
|
|
||||||
size_t chars = mbstowcs(NULL, ctx->value, 0);
|
size_t chars = mbstowcs(NULL, ctx->value, 0);
|
||||||
if (chars == (size_t)-1) {
|
if (chars == (size_t)-1) {
|
||||||
LOG_CONTEXTUAL_ERR("not a valid string value");
|
LOG_CONTEXTUAL_ERR("not a valid string value");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(*res);
|
||||||
*res = xmalloc((chars + 1) * sizeof(wchar_t));
|
*res = xmalloc((chars + 1) * sizeof(wchar_t));
|
||||||
mbstowcs(*res, ctx->value, chars + 1);
|
mbstowcs(*res, ctx->value, chars + 1);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1044,27 +1043,14 @@ parse_section_main(struct context *ctx)
|
||||||
else if (strcmp(key, "workers") == 0)
|
else if (strcmp(key, "workers") == 0)
|
||||||
return value_to_uint16(ctx, 10, &conf->render_worker_count);
|
return value_to_uint16(ctx, 10, &conf->render_worker_count);
|
||||||
|
|
||||||
else if (strcmp(key, "word-delimiters") == 0) {
|
else if (strcmp(key, "word-delimiters") == 0)
|
||||||
wchar_t *word_delimiters;
|
return value_to_wchars(ctx, &conf->word_delimiters);
|
||||||
if (!value_to_wchars(ctx, &word_delimiters))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
free(conf->word_delimiters);
|
|
||||||
conf->word_delimiters = word_delimiters;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (strcmp(key, "jump-label-letters") == 0) {
|
else if (strcmp(key, "jump-label-letters") == 0) {
|
||||||
deprecated_url_option(
|
deprecated_url_option(
|
||||||
conf, "jump-label-letters", "label-letters", path, lineno);
|
conf, "jump-label-letters", "label-letters", path, lineno);
|
||||||
|
|
||||||
wchar_t *letters;
|
return value_to_wchars(ctx, &conf->url.label_letters);
|
||||||
if (!value_to_wchars(ctx, &letters))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
free(conf->url.label_letters);
|
|
||||||
conf->url.label_letters = letters;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "notify") == 0)
|
else if (strcmp(key, "notify") == 0)
|
||||||
|
|
@ -1203,14 +1189,8 @@ parse_section_url(struct context *ctx)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "label-letters") == 0) {
|
else if (strcmp(key, "label-letters") == 0)
|
||||||
wchar_t *letters;
|
return value_to_wchars(ctx, &conf->url.label_letters);
|
||||||
if (!value_to_wchars(ctx, &letters))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
free(conf->url.label_letters);
|
|
||||||
conf->url.label_letters = letters;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (strcmp(key, "osc8-underline") == 0) {
|
else if (strcmp(key, "osc8-underline") == 0) {
|
||||||
_Static_assert(sizeof(conf->url.osc8_underline) == sizeof(int),
|
_Static_assert(sizeof(conf->url.osc8_underline) == sizeof(int),
|
||||||
|
|
@ -1273,18 +1253,15 @@ parse_section_url(struct context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "uri-characters") == 0) {
|
else if (strcmp(key, "uri-characters") == 0) {
|
||||||
wchar_t *uri_characters;
|
if (!value_to_wchars(ctx, &conf->url.uri_characters))
|
||||||
if (!value_to_wchars(ctx, &uri_characters))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
free(conf->url.uri_characters);
|
|
||||||
|
|
||||||
qsort(
|
qsort(
|
||||||
uri_characters,
|
conf->url.uri_characters,
|
||||||
wcslen(uri_characters),
|
wcslen(conf->url.uri_characters),
|
||||||
sizeof(uri_characters[0]),
|
sizeof(conf->url.uri_characters[0]),
|
||||||
&wccmp);
|
&wccmp);
|
||||||
conf->url.uri_characters = uri_characters;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue