diff options
| author | Jeff King <peff@peff.net> | 2026-02-15 04:05:34 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-02-17 09:45:29 -0800 |
| commit | 2ec30e71f44233b9afceda0f2992029674187674 (patch) | |
| tree | 9e8d5cd76255b4bd4d40c8bed29c406461586930 /contrib/persistent-https | |
| parent | 87cb6dc9b0832683a31d0c3126ecad4ad444489c (diff) | |
| download | git-2ec30e71f44233b9afceda0f2992029674187674.tar.gz git-2ec30e71f44233b9afceda0f2992029674187674.zip | |
ref-filter: simplify rstrip_ref_components() memory handling
We're stripping path components from the end of a string, which we do by
assigning a NUL as we parse each component, shortening the string. This
requires an extra temporary buffer to avoid munging our input string.
But the way that we allocate the buffer is unusual. We have an extra
"to_free" variable. Usually this is used when the access variable is
conceptually const, like:
const char *foo;
char *to_free = NULL;
if (...)
foo = to_free = xstrdup(...);
else
foo = some_const_string;
...
free(to_free);
But that's not what's happening here. Our "start" variable always points
to the allocated buffer, and to_free is redundant. Worse, it is marked
as const itself, requiring a cast when we free it.
Let's drop to_free entirely, and mark "start" as non-const, making the
memory handling more clear. As a bonus, this also silences a warning
from glibc-2.43 that our call to strrchr() implicitly strips away the
const-ness of "start".
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/persistent-https')
0 files changed, 0 insertions, 0 deletions
