commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd] 03/15: console-client: fix binary search


From: Samuel Thibault
Subject: [hurd] 03/15: console-client: fix binary search
Date: Sun, 05 Jul 2015 00:41:59 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 7410d78ed496c66a6c1d806360d1f83aa3321c01
Author: Justus Winter <address@hidden>
Date:   Sat May 23 10:51:05 2015 +0200

    console-client: fix binary search
    
    Previously, the binary search through the keysym map was incorrectly
    implemented.  This resulted in infinite loops (thanks to the compilers
    tail call optimization) or crashes (if the stack space was exhausted).
    
    * console-client/xkb/kstoucs.c (find_ucs): Fix binary search.
---
 console-client/xkb/kstoucs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/console-client/xkb/kstoucs.c b/console-client/xkb/kstoucs.c
index 81e71b9..8471e94 100644
--- a/console-client/xkb/kstoucs.c
+++ b/console-client/xkb/kstoucs.c
@@ -13,8 +13,10 @@ find_ucs (int keysym, struct ksmap *first, struct ksmap 
*last)
 
   if (middle->keysym == keysym)
     return middle->ucs; /* base case: needle found. */
-  else if (middle == first && middle == last)
-    return 0; /* base case: empty search space. */
+  else if (first == last               /* empty search space */
+           || keysym < first->keysym   /* lookup failure */
+           || keysym > last->keysym)   /* lookup failure */
+    return 0;
   /* recursive cases: halve search space. */
   else if (middle->keysym < keysym)
     return find_ucs (keysym, middle+1, last);

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]