git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH] test-dir-iterator: use path argument directly
@ 2019-08-07 11:15 René Scharfe
  2019-08-07 13:57 ` Derrick Stolee
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-08-07 11:15 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Daniel Ferreira

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] test-dir-iterator: use path argument directly
  2019-08-07 11:15 [PATCH] test-dir-iterator: use path argument directly René Scharfe
@ 2019-08-07 13:57 ` Derrick Stolee
  0 siblings, 0 replies; 2+ messages in thread
From: Derrick Stolee @ 2019-08-07 13:57 UTC (permalink / raw)
  To: René Scharfe, Git Mailing List; +Cc: Junio C Hamano, Daniel Ferreira

On 8/7/2019 7:15 AM, René Scharfe wrote:
> 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);

LGTM. I had a minor brain fart regarding the type of *argv and how the
const plays in, but dir_iterator_begin takes a "const char *" so this
is safe.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07 11:15 [PATCH] test-dir-iterator: use path argument directly René Scharfe
2019-08-07 13:57 ` Derrick Stolee

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git