mirror of
https://github.com/git/git.git
synced 2025-12-18 12:00:25 +01:00
We read the input into a strbuf, so we must free it. Without this, t1016 complains in SANITIZE=leak mode. The bug was introduced in7673ecd2dc(t1016-compatObjectFormat: add tests to verify the conversion between objects, 2023-10-01). But nobody seems to have noticed, probably because CI did not run these tests until the fix in6cd8369ef3(t/lib-gpg: call prepare_gnupghome() in GPG2 prereq, 2024-07-03). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
#include "test-tool.h"
|
|
#include "gpg-interface.h"
|
|
#include "strbuf.h"
|
|
|
|
|
|
int cmd__delete_gpgsig(int argc, const char **argv)
|
|
{
|
|
struct strbuf buf = STRBUF_INIT;
|
|
const char *pattern = "gpgsig";
|
|
const char *bufptr, *tail, *eol;
|
|
int deleting = 0;
|
|
size_t plen;
|
|
|
|
if (argc >= 2) {
|
|
pattern = argv[1];
|
|
argv++;
|
|
argc--;
|
|
}
|
|
|
|
plen = strlen(pattern);
|
|
strbuf_read(&buf, 0, 0);
|
|
|
|
if (!strcmp(pattern, "trailer")) {
|
|
size_t payload_size = parse_signed_buffer(buf.buf, buf.len);
|
|
fwrite(buf.buf, 1, payload_size, stdout);
|
|
goto out;
|
|
}
|
|
|
|
bufptr = buf.buf;
|
|
tail = bufptr + buf.len;
|
|
|
|
while (bufptr < tail) {
|
|
/* Find the end of the line */
|
|
eol = memchr(bufptr, '\n', tail - bufptr);
|
|
if (!eol)
|
|
eol = tail;
|
|
|
|
/* Drop continuation lines */
|
|
if (deleting && (bufptr < eol) && (bufptr[0] == ' ')) {
|
|
bufptr = eol + 1;
|
|
continue;
|
|
}
|
|
deleting = 0;
|
|
|
|
/* Does the line match the prefix? */
|
|
if (((bufptr + plen) < eol) &&
|
|
!memcmp(bufptr, pattern, plen) &&
|
|
(bufptr[plen] == ' ')) {
|
|
deleting = 1;
|
|
bufptr = eol + 1;
|
|
continue;
|
|
}
|
|
|
|
/* Print all other lines */
|
|
fwrite(bufptr, 1, (eol - bufptr) + 1, stdout);
|
|
bufptr = eol + 1;
|
|
}
|
|
|
|
out:
|
|
fflush(stdout);
|
|
strbuf_release(&buf);
|
|
return 0;
|
|
}
|