Re: [PATCH] fix incorrect line number report for bad gitconfig

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Stenberg <martin@xxxxxxxxxxx> writes:

> From c88f00e06cb877f9d944fdec480f53a7a42dd990 Mon Sep 17 00:00:00 2001
> From: Martin Stenberg <martin@xxxxxxxxxxx>
> Date: Fri, 9 Mar 2012 22:57:54 +0100
> Subject: [PATCH] fix incorrect line number report for bad gitconfig

Please drop these four lines. The commit object name is no use to
me, and the other lines duplicate what you have in the mail header.

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

If you say ".gitconfig", it gives a false impression to the readers
that this is only limited to parsing of $HOME/.gitconfig, which is
not the problem you are addressing.  "A section in a config file"
would be a better phrasing.

s/beeing/being/;

> 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@xxxxxxxxxxx>

Please have a paragraph break before your S-o-b: line.

Thanks. Review of the patch text follows.

> ---
>  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--;
> ...
>  		}

We might want to consolidate the error-return codepath in this
function to a single place by judicious use of "goto", perhaps like
this:

 config.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index ad03908..e222e85 100644
--- a/config.c
+++ b/config.c
@@ -287,7 +287,7 @@ static int get_extended_base_var(char *name, int baselen, int c)
 {
 	do {
 		if (c == '\n')
-			return -1;
+			goto error_incomplete_line;
 		c = get_next_char();
 	} while (isspace(c));
 
@@ -299,13 +299,13 @@ static int get_extended_base_var(char *name, int baselen, int c)
 	for (;;) {
 		int c = get_next_char();
 		if (c == '\n')
-			return -1;
+			goto error_incomplete_line;
 		if (c == '"')
 			break;
 		if (c == '\\') {
 			c = get_next_char();
 			if (c == '\n')
-				return -1;
+				goto error_incomplete_line;
 		}
 		name[baselen++] = c;
 		if (baselen > MAXNAME / 2)
@@ -316,6 +316,9 @@ static int get_extended_base_var(char *name, int baselen, int c)
 	if (get_next_char() != ']')
 		return -1;
 	return baselen;
+error_incomplete_line:
+	cf->linenr--;
+	return -1;
 }
 
 static int get_base_var(char *name)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]