Bug fix for ring and checkbox menu items

Martin T Jones <[email protected]> Wed, 26 Dec 2012 21:44:30 +0000
Newsgroups gmane.comp.sysutils.lcdproc
Message-ID <[email protected]>
Hello,

I hope everyone had a merry Christmas.

I have attached a patch to 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.

Happy New Year

Martin

_______________________________________________
LCDproc mailing list
[email protected]
http://lists.omnipotent.net/mailman/listinfo/lcdproc
ring.patch (text/x-patch, 1.3 KB)
Index: server/menu.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/menu.c,v
retrieving revision 1.43
diff -u -r1.43 menu.c
--- server/menu.c	1 Sep 2012 21:24:39 -0000	1.43
+++ server/menu.c	26 Dec 2012 21:30:20 -0000
@@ -734,18 +734,20 @@
 			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);