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

Re: clang static analyzer

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 7, 2009, 00:18 UTC
Message-ID
<7vtyw3d4cn.fsf@alter.siamese.dyndns.org>
In-Reply-To
<33ABC714-2BCC-4910-BCAE-D331AAF2A724@dbservice.com>
Tomas Carnecky <tom@dbservice.com> writes:
> pretty.c:get_header() - if 'line' doesn't contain a newline character,
> line is set to NULL on first iteration and then passed to strchr() in
> the second itration.
Thanks.

In practice, we will always have a newline, as we are reading from a valid commit object in this codepath.

 pretty.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/pretty.c b/pretty.c
index 8f5bd1a..7eb5384 100644
--- a/pretty.c
+++ b/pretty.c
@@ -245,11 +245,11 @@ static char *get_header(const struct commit *commit, const char *key)
 	int key_len = strlen(key);
 	const char *line = commit->buffer;
 
-	for (;;) {
+	while (line) {
 		const char *eol = strchr(line, '\n'), *next;
 
 		if (line == eol)
-			return NULL;
+			break;
 		if (!eol) {
 			eol = line + strlen(line);
 			next = NULL;
@@ -262,6 +262,7 @@ static char *get_header(const struct commit *commit, const char *key)
 		}
 		line = next;
 	}
+	return NULL;
 }
 
 static char *replace_encoding_header(char *buf, const char *encoding)
Previous: Nicolas SebrechtNext: Junio C Hamano
Message 6 of 7 in “clang static analyzer”
  1. Tomas CarneckyDec 6, 2009
  2. Jeff KingDec 6, 2009
  3. Nicolas PitreDec 6, 2009
  4. Jeff KingDec 6, 2009
  5. Nicolas SebrechtDec 6, 2009
  6. Junio C HamanoDec 7, 2009
  7. Junio C HamanoDec 7, 2009

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.