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

[PATCH] fix incorrect line number report for bad gitconfig

From
MSMartin Stenberg <martin@gnutiken.se>
Date
Mar 9, 2012, 22:30 UTC
Message-ID
<20120309223014.GA6380@gnutiken.se>
From c88f00e06cb877f9d944fdec480f53a7a42dd990 Mon Sep 17 00:00:00 2001
From: Martin Stenberg <martin@gnutiken.se>
Date: Fri, 9 Mar 2012 22:57:54 +0100
Subject: [PATCH] fix incorrect line number report for bad gitconfig

A .gitconfig section with a missing "]" reports the next line as beeing bad, same goes to a value with a missing end quote.

This happens because the error is not detected until the end of the line, when
line number is already increased. Fix this issue by decreasing line number by
one for these cases.
Signed-off-by: Martin Stenberg <martin@gnutiken.se>
---
 config.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/config.c b/config.c
index ad03908..8d96ba1 100644
--- a/config.c
+++ b/config.c
@@ -196,8 +196,10 @@ static char *parse_value(void)
 	for (;;) {
 		int c = get_next_char();
 		if (c == '\n') {
-			if (quote)
+			if (quote) {
+				cf->linenr--;
 				return NULL;
+			}
 			return cf->value.buf;
 		}
 		if (comment)
@@ -286,8 +288,10 @@ static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
 static int get_extended_base_var(char *name, int baselen, int c)
 {
 	do {
-		if (c == '\n')
+		if (c == '\n') {
+			cf->linenr--;
 			return -1;
+		}
 		c = get_next_char();
 	} while (isspace(c));
 
@@ -298,14 +302,18 @@ static int get_extended_base_var(char *name, int baselen, int c)
 
 	for (;;) {
 		int c = get_next_char();
-		if (c == '\n')
+		if (c == '\n') {
+			cf->linenr--;
 			return -1;
+		}
 		if (c == '"')
 			break;
 		if (c == '\\') {
 			c = get_next_char();
-			if (c == '\n')
+			if (c == '\n') {
+				cf->linenr--;
 				return -1;
+			}
 		}
 		name[baselen++] = c;
 		if (baselen > MAXNAME / 2)
-- 
1.7.9.1
Next: Junio C Hamano
Message 1 of 4 in “fix incorrect line number report for bad gitconfig”
  1. fix incorrect line number report for bad gitconfigMartin Stenberg, Mar 9, 2012
  2. Junio C HamanoMar 9, 2012
  3. Junio C HamanoMar 12, 2012
  4. Martin StenbergMar 12, 2012

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.