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)