Skip to content

Commit 28dc26d

Browse files
rscharfegitster
authored andcommitted
commit: remove find_header_mem()
cfc5cf4 (receive-pack.c: consolidate find header logic, 2022-01-06) introduced find_header_mem() and turned find_commit_header() into a thin wrapper. Since then, the latter has become the last remaining caller of the former. Remove it to restore find_commit_header() to the state before cfc5cf4, get rid of a strlen(3) call and resolve a NEEDSWORK note in the process. Signed-off-by: René Scharfe <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 020456c commit 28dc26d

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

commit.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,20 +1737,12 @@ struct commit_list **commit_list_append(struct commit *commit,
17371737
return &new_commit->next;
17381738
}
17391739

1740-
const char *find_header_mem(const char *msg, size_t len,
1741-
const char *key, size_t *out_len)
1740+
const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
17421741
{
17431742
int key_len = strlen(key);
17441743
const char *line = msg;
17451744

1746-
/*
1747-
* NEEDSWORK: It's possible for strchrnul() to scan beyond the range
1748-
* given by len. However, current callers are safe because they compute
1749-
* len by scanning a NUL-terminated block of memory starting at msg.
1750-
* Nonetheless, it would be better to ensure the function does not look
1751-
* at msg beyond the len provided by the caller.
1752-
*/
1753-
while (line && line < msg + len) {
1745+
while (line) {
17541746
const char *eol = strchrnul(line, '\n');
17551747

17561748
if (line == eol)
@@ -1767,10 +1759,6 @@ const char *find_header_mem(const char *msg, size_t len,
17671759
return NULL;
17681760
}
17691761

1770-
const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
1771-
{
1772-
return find_header_mem(msg, strlen(msg), key, out_len);
1773-
}
17741762
/*
17751763
* Inspect the given string and determine the true "end" of the log message, in
17761764
* order to find where to put a new Signed-off-by trailer. Ignored are

commit.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,12 @@ void free_commit_extra_headers(struct commit_extra_header *extra);
280280

281281
/*
282282
* Search the commit object contents given by "msg" for the header "key".
283-
* Reads up to "len" bytes of "msg".
284283
* Returns a pointer to the start of the header contents, or NULL. The length
285284
* of the header, up to the first newline, is returned via out_len.
286285
*
287286
* Note that some headers (like mergetag) may be multi-line. It is the caller's
288287
* responsibility to parse further in this case!
289288
*/
290-
const char *find_header_mem(const char *msg, size_t len,
291-
const char *key,
292-
size_t *out_len);
293-
294289
const char *find_commit_header(const char *msg, const char *key,
295290
size_t *out_len);
296291

0 commit comments

Comments
 (0)