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

[PATCH] grep: use return value of strbuf_detach()

From
René Scharfe <l.s.r@web.de>
Date
Aug 25, 2019, 13:26 UTC
Message-ID
<caf49742-65ee-7b2a-0179-ee11822b2350@web.de>

Append the strbuf buffer only after detaching it. There is no practical difference here, as the strbuf is not empty and no strbuf_ function is called between storing the pointer to the still attached buffer and calling strbuf_detach(), so that pointer is valid, but make sure to follow the standard sequence anyway for consistency.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/grep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 2699001fbd..69ac053acc 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1110,8 +1110,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			strbuf_addf(&buf, "+/%s%s",
 					strcmp("less", pager) ? "" : "*",
 					opt.pattern_list->pattern);
-			string_list_append(&path_list, buf.buf);
-			strbuf_detach(&buf, NULL);
+			string_list_append(&path_list,
+					   strbuf_detach(&buf, NULL));
 		}
 	}

--
2.23.0
Next: Johannes Schindelin
Message 1 of 2 in “grep: use return value of strbuf_detach()”
  1. grep: use return value of strbuf_detach()René Scharfe, Aug 25, 2019
  2. Johannes SchindelinAug 26, 2019

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.