From 2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a Mon Sep 17 00:00:00 2001 From: Rohit Mani Date: Fri, 7 Mar 2014 22:48:31 -0800 Subject: 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 Signed-off-by: Rohit Mani Signed-off-by: Junio C Hamano --- pretty.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index 87db08bd7..99ba8ae97 100644 --- a/pretty.c +++ b/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; -- cgit v1.2.1