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

[PATCH] setup.c: Remove duplicate code from prefix_pathspec()

From
LFLukas Fleischer <git@cryptocrack.de>
Date
Mar 14, 2013, 00:24 UTC
Message-ID
<1363220695-27911-1-git-send-email-git@cryptocrack.de>

Only check for ',' explicitly and handle both ')' and '\0' in the else branch. strcspn() can only return ',', ')' and '\0' at this point so the new code is completely equivalent to what we had before.

This also fixes following GCC warning:
    setup.c: In function ‘get_pathspec’:
    setup.c:207:8: warning: ‘nextat’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    setup.c:205:15: note: ‘nextat’ was declared here
Signed-off-by: Lukas Fleischer <git@cryptocrack.de>
---
This removes the only warning that currently occurs when building the
next branch.
Junio: Feel free to squash this into Andrew's patch (805da4dee15b,
"setup.c: stop prefix_pathspec() from looping past the end of string").
 setup.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/setup.c b/setup.c
index d2335a8..94c1e61 100644
--- a/setup.c
+++ b/setup.c
@@ -207,12 +207,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
 		     *copyfrom && *copyfrom != ')';
 		     copyfrom = nextat) {
 			size_t len = strcspn(copyfrom, ",)");
-			if (copyfrom[len] == '\0')
-				nextat = copyfrom + len;
-			else if (copyfrom[len] == ')')
-				nextat = copyfrom + len;
-			else if (copyfrom[len] == ',')
+			if (copyfrom[len] == ',')
 				nextat = copyfrom + len + 1;
+			else
+				/* handle ')' and '\0' */
+				nextat = copyfrom + len;
 			if (!len)
 				continue;
 			for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
-- 
1.8.2.rc2.352.g908df73
Message 1 of 1 in “setup.c: Remove duplicate code from prefix_pathspec()”
  1. setup.c: Remove duplicate code from prefix_pathspec()Lukas Fleischer, Mar 14, 2013

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.