Skip to content

Commit 93c432e

Browse files
committed
kconfig: fix line number in recursive inclusion detection
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>
1 parent 12e3342 commit 93c432e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/kconfig/lexer.l

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int text_size, text_asize;
3333
struct buffer {
3434
struct buffer *parent;
3535
YY_BUFFER_STATE state;
36+
int yylineno;
3637
};
3738

3839
static struct buffer *current_buf;
@@ -402,6 +403,7 @@ void zconf_nextfile(const char *name)
402403
struct buffer *buf = xmalloc(sizeof(*buf));
403404

404405
buf->state = YY_CURRENT_BUFFER;
406+
buf->yylineno = yylineno;
405407
buf->parent = current_buf;
406408
current_buf = buf;
407409
yyin = zconf_fopen(file->name);
@@ -412,7 +414,7 @@ void zconf_nextfile(const char *name)
412414
}
413415
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
414416

415-
current_file->lineno = yylineno;
417+
current_file->lineno = zconf_lineno();
416418
file->parent = current_file;
417419

418420
for (iter = current_file; iter; iter = iter->parent) {
@@ -425,7 +427,7 @@ void zconf_nextfile(const char *name)
425427
do {
426428
iter = iter->parent;
427429
fprintf(stderr, " included from: %s:%d\n",
428-
iter->name, iter->lineno - 1);
430+
iter->name, iter->lineno);
429431
} while (strcmp(iter->name, file->name));
430432
exit(1);
431433
}
@@ -440,15 +442,14 @@ static void zconf_endfile(void)
440442
struct buffer *tmp;
441443

442444
current_file = current_file->parent;
443-
if (current_file)
444-
yylineno = current_file->lineno;
445445

446446
if (!current_buf)
447447
return;
448448

449449
fclose(yyin);
450450
yy_delete_buffer(YY_CURRENT_BUFFER);
451451
yy_switch_to_buffer(current_buf->state);
452+
yylineno = current_buf->yylineno;
452453
tmp = current_buf;
453454
current_buf = current_buf->parent;
454455
free(tmp);

0 commit comments

Comments
 (0)