Endless loops in keyup/down handlers

Message ID 87vf089vli.fsf@kosh.bigo.ensc.de
State New
Headers

Commit Message

Enrico Scholz Oct. 8, 2005, 10 a.m. UTC
  Hello,

when MenuScrollWrap is activated, menues are going into an endless loop
when there are no selectable items. E.g. after 'Recordings' -> 1 -> Up,
vdr does not respond anymore. Same happens for non-empty menues which do
not have selectable items.

The attached patch fixes this (written for 1.3.33, but applies to 1.3.34
too).



Enrico
  

Patch

2005-10-03 17:52  Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
	- osdbase.c: prevent an endless loop in the keyup/down handlers
	  when no selectable entries are available and MenuScrollWrap
	  is activated

--- vdr-1.3.33/osdbase.c.noinfloop	2005-10-03 17:04:16.000000000 +0200
+++ vdr-1.3.33/osdbase.c	2005-10-03 17:04:51.000000000 +0200
@@ -266,14 +266,17 @@ 
   int tmpCurrent = current;
   int lastOnScreen = first + displayMenuItems - 1;
   int last = Count() - 1;
+  if (last==-1)
+     return;
+  
   while (--tmpCurrent != current) {
         if (tmpCurrent < 0) {
            if (Setup.MenuScrollWrap)
-              tmpCurrent = last;
+              tmpCurrent = last+1;
            else
               return;
            }
-        if (SelectableItem(tmpCurrent))
+	else if (SelectableItem(tmpCurrent))
            break;
         }
   if (first <= tmpCurrent && tmpCurrent <= lastOnScreen)
@@ -296,14 +299,17 @@ 
   int tmpCurrent = current;
   int lastOnScreen = first + displayMenuItems - 1;
   int last = Count() - 1;
+  if (last==-1)
+     return;
+  
   while (++tmpCurrent != current) {
         if (tmpCurrent > last) {
            if (Setup.MenuScrollWrap)
-              tmpCurrent = 0;
+              tmpCurrent = -1;
            else
               return;
            }
-        if (SelectableItem(tmpCurrent))
+        else if (SelectableItem(tmpCurrent))
            break;
         }
   if (first <= tmpCurrent && tmpCurrent <= lastOnScreen)