]> git.ipfire.org Git - thirdparty/git.git/commit
fast-export: do not modify memory from get_commit_buffer
authorLuke Shumaker <lukeshu@datawire.io>
Mon, 10 Mar 2025 15:57:45 +0000 (16:57 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Mar 2025 20:24:56 +0000 (13:24 -0700)
commitdda9bff3c55e45ee8dbfb49fd972c4b35fd4ba7e
treee79b3aa3dac8976ce194aa44fe3befdb3f0e81c9
parent87f2a9195e7bea721d9cffe98383b4065d233f66
fast-export: do not modify memory from get_commit_buffer

fast-export's helper function find_encoding() takes a `const char *`, but
modifies that memory despite the `const`.  Ultimately, this memory came
from get_commit_buffer(), and you're not supposed to modify the memory
that you get from get_commit_buffer().

So, get rid of find_encoding() in favor of commit.h:find_commit_header(),
which gives back a string length, rather than mutating the memory to
insert a '\0' terminator.

Because find_commit_header() detects the "\n\n" string that separates the
headers and the commit message, move the call to be above the
`message = strstr(..., "\n\n")` call.  This helps readability, and allows
for the value of `encoding` to be used for a better value of "..." so that
the same memory doesn't need to be checked twice.  Introduce a
`commit_buffer_cursor` variable to avoid writing an awkward
`encoding ? encoding + encoding_len : committer_end` expression.

Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c