From 991cf92594b78f3e95b65f0e2cc5e6e45040de9b Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Thu, 13 Oct 2022 03:14:08 +0300 Subject: [PATCH] sinowealth: print a warning if there are too much events in a macro --- src/driver-sinowealth.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/driver-sinowealth.c b/src/driver-sinowealth.c index 4de795ce..bd6034d4 100644 --- a/src/driver-sinowealth.c +++ b/src/driver-sinowealth.c @@ -1294,9 +1294,19 @@ sinowealth_update_macro_from_action(struct ratbag_profile *profile, struct ratba memset(¯o->events, 0, sizeof(macro->events)); unsigned int raw_event_count = 0; - for (unsigned int i = 0; i < MAX_MACRO_EVENTS && raw_event_count < SINOWEALTH_MACRO_LENGTH_MAX; ++i) { + for (unsigned int i = 0; i < MAX_MACRO_EVENTS; ++i) { struct ratbag_macro_event *event = &action->macro->events[i]; + if (raw_event_count >= SINOWEALTH_MACRO_LENGTH_MAX) { + log_error(device->ratbag, "There are more events in the macro than the mouse supports\n"); + + /* Update the type of this event so that libratbag ignores + * unused events. + */ + event->type = RATBAG_MACRO_EVENT_NONE; + break; + }; + if (action->macro->events[i].type == RATBAG_MACRO_EVENT_INVALID) break; if (action->macro->events[i].type == RATBAG_MACRO_EVENT_NONE)