From 1079bca3eb3a0943f116078be884c0d8d3188b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 26 Aug 2021 13:27:29 +0200 Subject: [PATCH] =?UTF-8?q?Silence=20=E2=80=9Cvariable=20length=20array=20?= =?UTF-8?q?bound=20evaluates=20to=20non-positive=20value=200=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bar/bar.c | 8 +++++--- modules/removables.c | 6 ++++-- modules/sway-xkb.c | 5 ++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bar/bar.c b/bar/bar.c index b29936b..2399368 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -25,6 +25,8 @@ #include "wayland.h" #endif +#define max(x, y) ((x) > (y) ? (x) : (y)) + /* * Calculate total width of left/center/rigth groups. * Note: begin_expose() must have been called @@ -293,9 +295,9 @@ run(struct bar *_bar) set_cursor(_bar, "left_ptr"); /* Start modules */ - thrd_t thrd_left[bar->left.count]; - thrd_t thrd_center[bar->center.count]; - thrd_t thrd_right[bar->right.count]; + thrd_t thrd_left[max(bar->left.count, 1)]; + thrd_t thrd_center[max(bar->center.count, 1)]; + thrd_t thrd_right[max(bar->right.count, 1)]; for (size_t i = 0; i < bar->left.count; i++) { struct module *mod = bar->left.mods[i]; diff --git a/modules/removables.c b/modules/removables.c index 4446f3d..a676ceb 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -23,6 +23,8 @@ #include "../particles/dynlist.h" #include "../plugin.h" +#define max(x, y) ((x) > (y) ? (x) : (y)) + typedef tll(char *) mount_point_list_t; struct partition { @@ -116,7 +118,7 @@ content(struct module *mod) } } - struct exposable *exposables[tll_length(partitions)]; + struct exposable *exposables[max(tll_length(partitions), 1)]; size_t idx = 0; tll_foreach(partitions, it) { @@ -621,7 +623,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) right_spacing != NULL ? yml_value_as_int(right_spacing) : 0; size_t ignore_count = ignore_list != NULL ? yml_list_length(ignore_list) : 0; - const char *ignore[ignore_count]; + const char *ignore[max(ignore_count, 1)]; if (ignore_list != NULL) { size_t i = 0; diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index 295b976..f4e7577 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -13,6 +13,8 @@ #include "i3-ipc.h" #include "i3-common.h" +#define max(x, y) ((x) > (y) ? (x) : (y)) + struct input { bool exists; char *identifier; @@ -65,7 +67,8 @@ content(struct module *mod) mtx_lock(&mod->lock); - struct exposable *particles[m->num_existing_inputs]; + struct exposable *particles[max(m->num_existing_inputs, 1)]; + for (size_t i = 0, j = 0; i < m->num_inputs; i++) { const struct input *input = &m->inputs[i];