[PATCH] Fix prefix match is treated as exact match

From: David Dufberg Tøttrup <david_AT_dufberg.se>
Date: Sat, 20 Aug 2016 16:20:19 +0200

Input text and items are only compared up to length of input but should be
compared against the full length of the item.
---
 dmenu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/dmenu.c b/dmenu.c
index 3b05752..ad3a2f1 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -198,7 +198,7 @@ match(void)
 
 	char buf[sizeof text], *s;
 	int i, tokc = 0;
-	size_t len, textsize;
+	size_t len, itemlen;
 	struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
 
 	strcpy(buf, text);
_AT_@ -209,15 +209,16 @@ match(void)
 	len = tokc ? strlen(tokv[0]) : 0;
 
 	matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
-	textsize = strlen(text);
 	for (item = items; item && item->text; item++) {
 		for (i = 0; i < tokc; i++)
 			if (!fstrstr(item->text, tokv[i]))
 				break;
 		if (i != tokc) /* not all tokens match */
 			continue;
+
+		itemlen = strlen(item->text);
 		/* exact matches go first, then prefixes, then substrings */
-		if (!tokc || !fstrncmp(text, item->text, textsize))
+		if (!tokc || !fstrncmp(text, item->text, itemlen))
 			appenditem(item, &matches, &matchend);
 		else if (!fstrncmp(tokv[0], item->text, len))
 			appenditem(item, &lprefix, &prefixend);
-- 
2.7.4
--------------F09E9F238D41CCCABFE69258--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sun Aug 21 2016 - 02:00:14 CEST