diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-01-12 14:36:09 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-01-12 14:36:09 -0800 |
commit | 8cc43dafc8f0d4ca04aa162573a44016f45ea364 (patch) | |
tree | 060b49468c211f1a8cdc8b02347ea7882d1e26a4 /src/modules | |
parent | 7aeaad3e34413e7bdf78696484fa6c502c5e0617 (diff) |
modules/compose: fix segfault introduced by 83e41d
It was assumed (n_modules - n_overlayable) would give the number
of non-overlayable modules appropriate as base layers. But with
the skipping of hermetic and experimental modules the base_idx
could be out of reach leaving layers NULL after the loop, which
will segfault later when strlen() assumes it's non-NULL.
This commit does the simple thing and also counts the unusable
modules to subtract from those eligible for base layers along
with n_overlayable.
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/compose/compose.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/modules/compose/compose.c b/src/modules/compose/compose.c index f3a1442..38ea539 100644 --- a/src/modules/compose/compose.c +++ b/src/modules/compose/compose.c @@ -171,21 +171,24 @@ static void compose_render_fragment(til_module_context_t *context, til_stream_t /* return a randomized valid layers= setting */ static char * compose_random_layers_setting(unsigned seed) { - size_t n_modules, n_rand_overlays, n_overlayable = 0, base_idx; + size_t n_modules, n_rand_overlays, n_overlayable = 0, n_unusable = 0, base_idx; char *layers = NULL; const til_module_t **modules; til_get_modules(&modules, &n_modules); for (size_t i = 0; i < n_modules; i++) { - if ((modules[i]->flags & (TIL_MODULE_HERMETIC | TIL_MODULE_EXPERIMENTAL))) + if ((modules[i]->flags & (TIL_MODULE_HERMETIC | TIL_MODULE_EXPERIMENTAL))) { + n_unusable++; + continue; + } if (modules[i]->flags & TIL_MODULE_OVERLAYABLE) n_overlayable++; } - base_idx = rand_r(&seed) % (n_modules - n_overlayable); + base_idx = rand_r(&seed) % (n_modules - (n_overlayable + n_unusable)); for (size_t i = 0, j = 0; !layers && i < n_modules; i++) { if ((modules[i]->flags & (TIL_MODULE_HERMETIC | TIL_MODULE_EXPERIMENTAL))) continue; |