git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] pretty: simplify input line length calculation in pp_user_info()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Apr 25, 2013, 19:40 UTC
Message-ID
<517986A9.4060506@lsrfire.ath.cx>

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
Next: René Scharfe
Message 1 of 3 in “pretty: simplify input line length calculation in pp_user_info()”
  1. 1/3 pretty: simplify input line length calculation in pp_user_info()René Scharfe, Apr 25, 2013
  2. 2/3 pretty: simplify output line length calculation in pp_user_info()René Scharfe, Apr 25, 2013
  3. 3/3 pretty: remove intermediate strbufs from pp_user_info()René Scharfe, Apr 25, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.