Thread (1 message) 1 message, 1 author, 2016-06-15

Re: clang static analyzer

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:50
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Tomas Carnecky [off-list ref] 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)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help