From 9d1b43d241add6f26dc65d181debc514ce6238f3 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 15 Jun 2019 13:50:33 -0700 Subject: [PATCH] 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 --- src/libinput-util.c | 6 +++--- src/quirks.c | 4 ++-- test/test-keyboard.c | 4 ++-- test/test-pointer.c | 4 ++-- test/test-utils.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libinput-util.c b/src/libinput-util.c index 41f9dae..dcc4a16 100644 --- a/src/libinput-util.c +++ b/src/libinput-util.c @@ -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); diff --git a/src/quirks.c b/src/quirks.c index e2e8b4f..7e66d1c 100644 --- a/src/quirks.c +++ b/src/quirks.c @@ -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) diff --git a/test/test-keyboard.c b/test/test-keyboard.c index 4b6b531..f5b566d 100644 --- a/test/test-keyboard.c +++ b/test/test-keyboard.c @@ -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; diff --git a/test/test-pointer.c b/test/test-pointer.c index 2d71d50..25cef85 100644 --- a/test/test-pointer.c +++ b/test/test-pointer.c @@ -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; diff --git a/test/test-utils.c b/test/test-utils.c index 356cd43..0cde5aa 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -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); -- 2.7.4