Commit 7bdfc0a68506709b05c40ac519ded044a5ad7124

Patrick Steinhardt 2017-07-14T15:33:32

parse: always initialize line pointer Upon initializing the parser context, we do not currently initialize the current line, line length and line number. Do so in order to make the interface easier to use and more obvious for future consumers of the parsing API.

diff --git a/src/parse.c b/src/parse.c
index c1bd213..6b8902c 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -16,6 +16,9 @@ int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_l
 	ctx->content_len = content_len;
 	ctx->remain = ctx->content;
 	ctx->remain_len = ctx->content_len;
+	ctx->line = ctx->remain;
+	ctx->line_len = git__linenlen(ctx->line, ctx->remain_len);
+	ctx->line_num = 1;
 
 	return 0;
 }
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 8b0a5d3..fee6afa 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -613,10 +613,7 @@ static int parse_patch_header(
 {
 	int error = 0;
 
-	for (ctx->parse_ctx.line = ctx->parse_ctx.remain;
-		ctx->parse_ctx.remain_len > 0;
-		git_parse_advance_line(&ctx->parse_ctx)) {
-
+	for (; ctx->parse_ctx.remain_len > 0; git_parse_advance_line(&ctx->parse_ctx)) {
 		/* This line is too short to be a patch header. */
 		if (ctx->parse_ctx.line_len < 6)
 			continue;