aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/ls-files.c
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2023-03-10 13:04:33 +0000
committerJunio C Hamano <gitster@pobox.com>2023-03-10 09:16:16 -0800
commitcfb62dd006ae82dd1e06fb177095c8885b40b1c3 (patch)
tree6c995a3f114d4c4ab06295722a45cadf79b45265 /builtin/ls-files.c
parentce74de931d7aea9746e37632534eacc63b0c1a90 (diff)
downloadgit-cfb62dd006ae82dd1e06fb177095c8885b40b1c3.tar.gz
ls-files: fix "--format" output of relative paths
Fix a bug introduced with the "--format" option in ce74de93 (ls-files: introduce "--format" option, 2022-07-23), where relative paths were computed using the output buffer, which could lead to random garbage data in the output. Signed-off-by: Adam Johnson <me@adamj.eu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/ls-files.c')
-rw-r--r--builtin/ls-files.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 779dc18e59..c6484fdb45 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -89,12 +89,15 @@ static void write_name(const char *name)
static void write_name_to_buf(struct strbuf *sb, const char *name)
{
- const char *rel = relative_path(name, prefix_len ? prefix : NULL, sb);
+ struct strbuf buf = STRBUF_INIT;
+ const char *rel = relative_path(name, prefix_len ? prefix : NULL, &buf);
if (line_terminator)
quote_c_style(rel, sb, NULL, 0);
else
strbuf_addstr(sb, rel);
+
+ strbuf_release(&buf);
}
static const char *get_tag(const struct cache_entry *ce, const char *tag)