use strchrnul() in place of strchr() and strlen()
Avoid scanning strings twice, once with strchr() and then with strlen(), by using strchrnul(). Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rohit Mani <rohit.mani@outlook.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
5f95c9f850
commit
2c5495f7b6
5
pretty.c
5
pretty.c
@ -549,14 +549,13 @@ static char *get_header(const struct commit *commit, const char *msg,
|
||||
const char *line = msg;
|
||||
|
||||
while (line) {
|
||||
const char *eol = strchr(line, '\n'), *next;
|
||||
const char *eol = strchrnul(line, '\n'), *next;
|
||||
|
||||
if (line == eol)
|
||||
return NULL;
|
||||
if (!eol) {
|
||||
if (!*eol) {
|
||||
warning("malformed commit (header is missing newline): %s",
|
||||
sha1_to_hex(commit->object.sha1));
|
||||
eol = line + strlen(line);
|
||||
next = NULL;
|
||||
} else
|
||||
next = eol + 1;
|
||||
|
||||
Reference in New Issue
Block a user