config.c: fix accuracy of line number in errors
[gitweb.git] / config.c
index 300d626018b18b87ad3d82a5926639d2207b7ada..22fef4050bb5d411ea991f5a84644b9308f2f836 100644 (file)
--- a/config.c
+++ b/config.c
@@ -244,6 +244,7 @@ static int get_next_char(void)
                cf->linenr++;
        if (c == EOF) {
                cf->eof = 1;
+               cf->linenr++;
                c = '\n';
        }
        return c;
@@ -319,6 +320,7 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
 {
        int c;
        char *value;
+       int ret;
 
        /* Get the full name */
        for (;;) {
@@ -341,7 +343,15 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
                if (!value)
                        return -1;
        }
-       return fn(name->buf, value, data);
+       /*
+        * We already consumed the \n, but we need linenr to point to
+        * the line we just parsed during the call to fn to get
+        * accurate line number in error messages.
+        */
+       cf->linenr--;
+       ret = fn(name->buf, value, data);
+       cf->linenr++;
+       return ret;
 }
 
 static int get_extended_base_var(struct strbuf *name, int c)