]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
kconfig: fix line number in recursive inclusion detection
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 7 Jan 2024 13:19:48 +0000 (22:19 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 19 Feb 2024 09:20:39 +0000 (18:20 +0900)
The error message shows a wrong line number if the 'source' directive
is wrapped to the following line.

[Test Code]

  source \
  "Kconfig"

This results in the following error message:

  Recursive inclusion detected.
  Inclusion path:
    current file : Kconfig
    included from: Kconfig:2

The correct message should be as follows:

  Recursive inclusion detected.
  Inclusion path:
    current file : Kconfig
    included from: Kconfig:1

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/lexer.l

index d75423ec4eae1684c26c283eeaba13aa338d820c..f93b535a080c00f03b6a08fc09d7acb9e70abb2c 100644 (file)
@@ -33,6 +33,7 @@ static int text_size, text_asize;
 struct buffer {
        struct buffer *parent;
        YY_BUFFER_STATE state;
+       int yylineno;
 };
 
 static struct buffer *current_buf;
@@ -402,6 +403,7 @@ void zconf_nextfile(const char *name)
        struct buffer *buf = xmalloc(sizeof(*buf));
 
        buf->state = YY_CURRENT_BUFFER;
+       buf->yylineno = yylineno;
        buf->parent = current_buf;
        current_buf = buf;
        yyin = zconf_fopen(file->name);
@@ -412,7 +414,7 @@ void zconf_nextfile(const char *name)
        }
        yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
 
-       current_file->lineno = yylineno;
+       current_file->lineno = zconf_lineno();
        file->parent = current_file;
 
        for (iter = current_file; iter; iter = iter->parent) {
@@ -425,7 +427,7 @@ void zconf_nextfile(const char *name)
                        do {
                                iter = iter->parent;
                                fprintf(stderr, "  included from: %s:%d\n",
-                                       iter->name, iter->lineno - 1);
+                                       iter->name, iter->lineno);
                        } while (strcmp(iter->name, file->name));
                        exit(1);
                }
@@ -440,8 +442,6 @@ static void zconf_endfile(void)
        struct buffer *tmp;
 
        current_file = current_file->parent;
-       if (current_file)
-               yylineno = current_file->lineno;
 
        if (!current_buf)
                return;
@@ -449,6 +449,7 @@ static void zconf_endfile(void)
        fclose(yyin);
        yy_delete_buffer(YY_CURRENT_BUFFER);
        yy_switch_to_buffer(current_buf->state);
+       yylineno = current_buf->yylineno;
        tmp = current_buf;
        current_buf = current_buf->parent;
        free(tmp);