summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorRohit Mani <rohit.mani@outlook.com>2014-03-08 06:48:31 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-03-10 15:35:30 (GMT)
commit2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a (patch)
tree9900454e2b547e2fee8e9e67b39ced68ea0c650e /pretty.c
parent5f95c9f850b19b368c43ae399cc831b17a26a5ac (diff)
downloadgit-2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a.zip
git-2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a.tar.gz
git-2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a.tar.bz2
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>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/pretty.c b/pretty.c
index 87db08b..99ba8ae 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;