Skip to content

Commit 30e77bc

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de5abe9 commit 30e77bc

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

pretty.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ void pp_user_info(const struct pretty_print_context *pp,
413413
struct strbuf name;
414414
struct strbuf mail;
415415
struct ident_split ident;
416-
int linelen;
417416
char *line_end;
418417
const char *mailbuf, *namebuf;
419418
size_t namelen, maillen;
@@ -422,18 +421,10 @@ void pp_user_info(const struct pretty_print_context *pp,
422421
if (pp->fmt == CMIT_FMT_ONELINE)
423422
return;
424423

425-
line_end = strchr(line, '\n');
426-
if (!line_end) {
427-
line_end = strchr(line, '\0');
428-
if (!line_end)
429-
return;
430-
}
431-
432-
linelen = ++line_end - line;
433-
if (split_ident_line(&ident, line, linelen))
424+
line_end = strchrnul(line, '\n');
425+
if (split_ident_line(&ident, line, line_end - line))
434426
return;
435427

436-
437428
mailbuf = ident.mail_begin;
438429
maillen = ident.mail_end - ident.mail_begin;
439430
namebuf = ident.name_begin;

0 commit comments

Comments
 (0)