summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2013-04-25 19:40:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-04-25 22:02:51 (GMT)
commit30e77bcb5008d1947c721fb084e21eeaa591c45e (patch)
tree5e4cf4c72115b69ac0e96cfa2b7a6f763c41c50d /pretty.c
parentde5abe9fe91a496d019d62abefe23df9d72fad30 (diff)
downloadgit-30e77bcb5008d1947c721fb084e21eeaa591c45e.zip
git-30e77bcb5008d1947c721fb084e21eeaa591c45e.tar.gz
git-30e77bcb5008d1947c721fb084e21eeaa591c45e.tar.bz2
pretty: simplify input line length calculation in pp_user_info()
Instead of searching for LF and NUL with two strchr() calls use a single strchrnul() call. We don't need to check if the returned pointer is NULL because either we'll find the NUL at the end of line, or the caller forgot to NUL-terminate the string and we'll overrun the buffer in any case. Also we don't need to pass LF or NUL to split_ident_line() as it ignores it anyway. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/pretty.c b/pretty.c
index acbfceb..a9c3581 100644
--- a/pretty.c
+++ b/pretty.c
@@ -413,7 +413,6 @@ void pp_user_info(const struct pretty_print_context *pp,
struct strbuf name;
struct strbuf mail;
struct ident_split ident;
- int linelen;
char *line_end;
const char *mailbuf, *namebuf;
size_t namelen, maillen;
@@ -422,18 +421,10 @@ void pp_user_info(const struct pretty_print_context *pp,
if (pp->fmt == CMIT_FMT_ONELINE)
return;
- line_end = strchr(line, '\n');
- if (!line_end) {
- line_end = strchr(line, '\0');
- if (!line_end)
- return;
- }
-
- linelen = ++line_end - line;
- if (split_ident_line(&ident, line, linelen))
+ line_end = strchrnul(line, '\n');
+ if (split_ident_line(&ident, line, line_end - line))
return;
-
mailbuf = ident.mail_begin;
maillen = ident.mail_end - ident.mail_begin;
namebuf = ident.name_begin;