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>

René Scharfe committed Apr 25, 2013 at 21:40 UTC 30e77bcb5008d1947c721fb084e21eeaa591c45e
1 file changed +2 -11
pretty.c
+2 -11
@@ -413,7 +413,6 @@ void pp_user_info(const struct pretty_print_context *pp,
413 struct strbuf name;
414 struct strbuf mail;
415 struct ident_split ident;
416 - int linelen;
416 char *line_end;
417 const char *mailbuf, *namebuf;
418 size_t namelen, maillen;
@@ -422,18 +421,10 @@ void pp_user_info(const struct pretty_print_context *pp,
421 if (pp->fmt == CMIT_FMT_ONELINE)
422 return;
423
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))
426 return;
427
436 -
428 mailbuf = ident.mail_begin;
429 maillen = ident.mail_end - ident.mail_begin;
430 namebuf = ident.name_begin;