git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] exclude: stricten a length check in EXC_FLAG_ENDSWITH case

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 14, 2012, 11:55 UTC
Message-ID
<1350215742-20761-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1350215742-20761-1-git-send-email-pclouds@gmail.com>

This block of code deals with the "basename" part only, which has the length of "pathlen - (basename - pathname)". Stricten the length check and remove "pathname" from the main expression to avoid confusion.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dir.c b/dir.c
index cddf043..d81498e 100644
--- a/dir.c
+++ b/dir.c
@@ -561,8 +561,9 @@ int excluded_from_list(const char *pathname,
 				if (!strcmp_icase(exclude, basename))
 					return to_exclude;
 			} else if (x->flags & EXC_FLAG_ENDSWITH) {
-				if (x->patternlen - 1 <= pathlen &&
-				    !strcmp_icase(exclude + 1, pathname + pathlen - x->patternlen + 1))
+				int len = pathlen - (basename - pathname);
+				if (x->patternlen - 1 <= len &&
+				    !strcmp_icase(exclude + 1, basename + len - x->patternlen + 1))
 					return to_exclude;
 			} else {
 				if (fnmatch_icase(exclude, basename, 0) == 0)
-- 
1.8.0.rc2.11.g2b79d01
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 2 of 6 in “nd/attr-match-optim-more updates”
  1. 0/4 nd/attr-match-optim-more updatesNguyễn Thái Ngọc Duy, Oct 14, 2012
  2. 1/4 exclude: stricten a length check in EXC_FLAG_ENDSWITH caseNguyễn Thái Ngọc Duy, Oct 14, 2012
  3. 2/4 exclude: fix a bug in prefix compare optimizationNguyễn Thái Ngọc Duy, Oct 14, 2012
  4. 3/4 exclude/attr: share basename matching codeNguyễn Thái Ngọc Duy, Oct 14, 2012
  5. Junio C HamanoOct 14, 2012
  6. 4/4 exclude/attr: share full pathname matching codeNguyễn Thái Ngọc Duy, Oct 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.