From 8e219de4793f426ed28238fe7a945cce98f2f4e9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 30 Aug 2023 21:58:57 -0700 Subject: modules/voronoi: handle baking errors in voronoi_setup() More setup_func conversion to returning the failed setting on errors during res_setup baking. --- src/modules/voronoi/voronoi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/modules') diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c index e4621ab..0c06c1d 100644 --- a/src/modules/voronoi/voronoi.c +++ b/src/modules/voronoi/voronoi.c @@ -368,7 +368,7 @@ til_module_t voronoi_module = { static int voronoi_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup) { - const char *n_cells; + til_setting_t *n_cells; const char *n_cells_values[] = { "512", "1024", @@ -379,7 +379,7 @@ static int voronoi_setup(const til_settings_t *settings, til_setting_t **res_set "32768", NULL }; - const char *randomize; + til_setting_t *randomize; const char *bool_values[] = { "off", "on", @@ -387,7 +387,7 @@ static int voronoi_setup(const til_settings_t *settings, til_setting_t **res_set }; int r; - r = til_settings_get_and_describe_value(settings, + r = til_settings_get_and_describe_setting(settings, &(til_setting_spec_t){ .name = "Voronoi cells quantity", .key = "cells", @@ -402,7 +402,7 @@ static int voronoi_setup(const til_settings_t *settings, til_setting_t **res_set if (r) return r; - r = til_settings_get_and_describe_value(settings, + r = til_settings_get_and_describe_setting(settings, &(til_setting_spec_t){ .name = "Constantly randomize cell placement", .key = "randomize", @@ -424,9 +424,10 @@ static int voronoi_setup(const til_settings_t *settings, til_setting_t **res_set if (!setup) return -ENOMEM; - sscanf(n_cells, "%zu", &setup->n_cells); + if (sscanf(n_cells->value, "%zu", &setup->n_cells) != 1) + return til_setup_free_with_failed_setting_ret_err(&setup->til_setup, n_cells, res_setting, -EINVAL); - if (!strcasecmp(randomize, "on")) + if (!strcasecmp(randomize->value, "on")) setup->randomize = 1; *res_setup = &setup->til_setup; -- cgit v1.2.3