Commit 9d1b43d2 authored by Michael Forney's avatar Michael Forney

Avoid unnecessary VLAs

When the array length is fixed, or bounded by a fixed upper bound,
just use that fixed length.
Signed-off-by: Michael Forney's avatarMichael Forney <mforney@mforney.org>
parent 4740ad7a
......@@ -470,7 +470,8 @@ parse_evcode_property(const char *prop, struct input_event *events, size_t *neve
bool rc = false;
size_t ncodes = 0;
size_t idx;
struct input_event evs[*nevents];
/* A randomly chosen max so we avoid crazy quirks */
struct input_event evs[32];
memset(evs, 0, sizeof evs);
......@@ -481,8 +482,7 @@ parse_evcode_property(const char *prop, struct input_event *events, size_t *neve
for (idx = 0; strv[idx]; idx++)
ncodes++;
/* A randomly chosen max so we avoid crazy quirks */
if (ncodes == 0 || ncodes > 32)
if (ncodes == 0 || ncodes > ARRAY_LENGTH(evs))
goto out;
ncodes = min(*nevents, ncodes);
......
......@@ -737,8 +737,8 @@ parse_attr(struct quirks_context *ctx,
p->value.s = safe_strdup(value);
rc = true;
} else if (streq(key, quirk_get_name(QUIRK_ATTR_EVENT_CODE_DISABLE))) {
size_t nevents = 32;
struct input_event events[nevents];
struct input_event events[32];
size_t nevents = ARRAY_LENGTH(events);
p->id = QUIRK_ATTR_EVENT_CODE_DISABLE;
if (!parse_evcode_property(value, events, &nevents) ||
nevents == 0)
......
......@@ -31,8 +31,8 @@
START_TEST(keyboard_seat_key_count)
{
const int num_devices = 4;
struct litest_device *devices[num_devices];
struct litest_device *devices[4];
const int num_devices = ARRAY_LENGTH(devices);
struct libinput *libinput;
struct libinput_event *ev;
struct libinput_event_keyboard *kev;
......
......@@ -800,8 +800,8 @@ END_TEST
START_TEST(pointer_seat_button_count)
{
const int num_devices = 4;
struct litest_device *devices[num_devices];
struct litest_device *devices[4];
const int num_devices = ARRAY_LENGTH(devices);
struct libinput *libinput;
struct libinput_event *ev;
struct libinput_event_pointer *tev;
......
......@@ -517,8 +517,8 @@ START_TEST(evcode_prop_parser)
for (int i = 0; tests[i].prop; i++) {
bool success;
size_t nevents = 32;
struct input_event events[nevents];
struct input_event events[32];
size_t nevents = ARRAY_LENGTH(events);
t = &tests[i];
success = parse_evcode_property(t->prop, events, &nevents);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment