grep: use return value of strbuf_detach()
authorRené Scharfe <l.s.r@web.de>
Sun, 25 Aug 2019 13:26:40 +0000 (15:26 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Aug 2019 18:32:28 +0000 (11:32 -0700)
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>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
index 2699001fbd6dfe07f0338ee478454ec2b7325559..69ac053acc16be6b12e0743dfabf8a481e1f92cb 100644 (file)
@@ -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));
                }
        }