dmenu incorrectly orders matching results:

$ dmenu <<EOF
suck xless
suck less
EOF

Typing 'suck less' shows 'suck xless' as first result, however, according to a
comment in the source code, this is not the intended behaviour:
    /* exact matches go first, then prefixes, then substrings */

The attached patch should fix the problem. Regarding the third argument to
fstrncmp: assuming fstrncmp, whatever it points to, behaves as strncmp (i.e.
"characters that follow a null byte are not compared"), both 'strlen(text) + 1'
and 'strlen(item->text) + 1' should be safe.
>From 2cbebb463164033d48a1420b2d0669ea81e92fff Mon Sep 17 00:00:00 2001
From: "Davide \"FunkyAss\" Del Zompo" <davide.delzo...@gmail.com>
Date: Fri, 14 Aug 2015 16:53:37 +0200
Subject: [PATCH] fix incorrect ordering of match results

look for exact matches comparing the user input against the item text
---
 dmenu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dmenu.c b/dmenu.c
index f0bc176..c3cb467 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -485,7 +485,7 @@ match(void) {
 		if(i != tokc) /* not all tokens match */
 			continue;
 		/* exact matches go first, then prefixes, then substrings */
-		if(!tokc || !fstrncmp(tokv[0], item->text, len+1))
+		if(!tokc || !fstrncmp(text, item->text, strlen(text) + 1))
 			appenditem(item, &matches, &matchend);
 		else if(!fstrncmp(tokv[0], item->text, len))
 			appenditem(item, &lprefix, &prefixend);
-- 
2.5.0

Reply via email to