Skip to content

Commit

Permalink
pretty: simplify input line length calculation in pp_user_info()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Apr 25, 2013
1 parent de5abe9 commit 30e77bc
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 30e77bc

Please sign in to comment.