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

[PATCH] test-dir-iterator: use path argument directly

From
René Scharfe <l.s.r@web.de>
Date
Aug 7, 2019, 11:15 UTC
Message-ID
<7f428974-9218-fa7c-6f3c-3c0db30a7fec@web.de>

Avoid allocating and leaking a strbuf for holding a verbatim copy of the path argument and pass the latter directly to dir_iterator_begin() instead.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
This test helper was added after v2.22.0 (2019-06-07) by 150791adbf
(dir-iterator: add tests for dir-iterator API, 2019-07-10).
 t/helper/test-dir-iterator.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c
index c7c30664da..659b6bfa81 100644
--- a/t/helper/test-dir-iterator.c
+++ b/t/helper/test-dir-iterator.c
@@ -19,7 +19,6 @@ static const char *error_name(int error_number)
  */
 int cmd__dir_iterator(int argc, const char **argv)
 {
-	struct strbuf path = STRBUF_INIT;
 	struct dir_iterator *diter;
 	unsigned int flags = 0;
 	int iter_status;
@@ -36,8 +35,7 @@ int cmd__dir_iterator(int argc, const char **argv)
 	if (!*argv || argc != 1)
 		die("dir-iterator needs exactly one non-option argument");

-	strbuf_add(&path, *argv, strlen(*argv));
-	diter = dir_iterator_begin(path.buf, flags);
+	diter = dir_iterator_begin(*argv, flags);

 	if (!diter) {
 		printf("dir_iterator_begin failure: %s\n", error_name(errno));
--
2.22.0
Next: Derrick Stolee
Message 1 of 2 in “test-dir-iterator: use path argument directly”
  1. test-dir-iterator: use path argument directlyRené Scharfe, Aug 7, 2019
  2. Derrick StoleeAug 7, 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.