From 12a4ecfbf413777c3ef98719e6b41993a9618903 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 26 May 2023 16:58:20 -0700 Subject: setup,til: assert(desc) if setup_func() wants more settings In this "all settings require descs" world, when setup_func forgets to return a res_desc for a setting it wants, we can end up in an infinite loop situation. It's better to abort immediately on the assert to catch such a program error. --- src/setup.c | 2 ++ src/til.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/setup.c b/src/setup.c index 30a5401..d2618ad 100644 --- a/src/setup.c +++ b/src/setup.c @@ -22,6 +22,8 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se /* TODO: regex and error handling */ while ((r = setup_func(settings, &setting, &desc, res_setup)) > 0) { + assert(desc); + additions++; /* if setup_func() has returned a description for an undescribed preexisting setting, diff --git a/src/til.c b/src/til.c index 38daac8..fad9383 100644 --- a/src/til.c +++ b/src/til.c @@ -348,6 +348,8 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se return -ENOMEM; for (setting = NULL; module->setup(settings, &setting, &desc, res_setup) > 0; setting = NULL) { + assert(desc); + if (!setting) { if (desc->spec.random) { char *value; -- cgit v1.2.3