From 370926811a08f673317e77c1156013ab7578267e Mon Sep 17 00:00:00 2001 From: mmdolze Date: Thu, 27 Dec 2012 11:49:29 +0000 Subject: [PATCH] Fix a problem when using the left key to change the ring and checkbox menu items. The old code used modulus which does not give the required result, for C (ISO 1990) and before the result is implementation defined so may have worked for some compilers / targets but from C (ISO 1999) onwards the sign of the result comes from the dividend so will not work. (By M. T. Jones) --- ChangeLog | 1 + server/menu.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 446e97e..0145bd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Key: * Something changed / fixed v0.5dev (ongoing development) + * Fix using the left key to change the ring and checkbox menu items * sed1520: Add an option for inverted segment mapping (idea by R. Buchert) v0.5.6 diff --git a/server/menu.c b/server/menu.c index aeb9767..086d80e 100644 --- a/server/menu.c +++ b/server/menu.c @@ -734,18 +734,20 @@ MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, unsi break; switch (subitem->type) { case MENUITEM_CHECKBOX: - /* Note: this works as CheckboxValue is an enum >= 0. */ - subitem->data.checkbox.value--; - subitem->data.checkbox.value %= (subitem->data.checkbox.allow_gray) ? 3 : 2; + if (subitem->data.checkbox.value == 0) + subitem->data.checkbox.value = (subitem->data.checkbox.allow_gray) ? 2 : 1; + else + subitem->data.checkbox.value--; if (subitem->event_func) subitem->event_func(subitem, MENUEVENT_UPDATE); return MENURESULT_NONE; case MENUITEM_RING: /* ring: jump to the end if beginning is reached */ - /* Note: this works as data.ring.value is a short >= 0 */ - subitem->data.ring.value--; - subitem->data.ring.value %= LL_Length(subitem->data.ring.strings); + if (subitem->data.ring.value == 0) + subitem->data.ring.value = LL_Length(subitem->data.ring.strings) - 1; + else + subitem->data.ring.value--; if (subitem->event_func) subitem->event_func(subitem, MENUEVENT_UPDATE);