git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] pretty: simplify input line length calculation in pp_user_info()
@ 2013-04-25 19:40 René Scharfe
  2013-04-25 19:41 ` [PATCH 2/3] pretty: simplify output " René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2013-04-25 19:40 UTC (permalink / raw)
  To: git discussion list; +Cc: Antoine Pelisse, Junio C Hamano

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>
---
 pretty.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/pretty.c b/pretty.c
index ba31481..e51c993 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;
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-25 19:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-25 19:40 [PATCH 1/3] pretty: simplify input line length calculation in pp_user_info() René Scharfe
2013-04-25 19:41 ` [PATCH 2/3] pretty: simplify output " René Scharfe
2013-04-25 19:43   ` [PATCH 3/3] pretty: remove intermediate strbufs from pp_user_info() René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).