threads / patch / 51729

patchgrep: use return value of strbuf_detach()

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

## tl;dr

2 messages between Aug 25, 2019 and Aug 26, 2019. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Aug 25, 2019, 13:26 UTC · lore

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(-)
Show changes to builtin/grep.c +2 −3
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
Johannes Schindelin· Aug 26, 2019, 14:58 UTC · re: René Scharfe · lore

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

Hi René,
On Sun, 25 Aug 2019, René Scharfe wrote:
Show 5 quoted lines
> 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.
ACK!

Thanks, Dscho

Show 24 quoted lines
>
> 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
>

← back to recent threads