Skip to content

Commit c226456

Browse files
rupranMichal Marek
authored andcommitted
kconfig: warn of unhandled characters in Kconfig commands
In Kconfig, definitions of options take the following form: "<COMMAND> <PARAM> <PARAM> ...". COMMANDs and PARAMs are treated slightly different by the underlying parser. While commit 2e0d737 ("kconfig: don't silently ignore unhandled characters") introduced a warning for unsupported characters around PARAMs, it does not cover situations where a COMMAND has additional characters before it. This change makes Kconfig emit a warning if superfluous characters are found before COMMANDs. As the 'help' statement sometimes is written as '---help---', the '-' character would now also be regarded as unhandled and generate a warning. To avoid that, '-' is added to the list of allowed characters, and the token '---help---' is included in the zconf.gperf file. Reported-by: Valentin Rothberg <[email protected]> Signed-off-by: Andreas Ruprecht <[email protected]> Reviewed-by: Ulf Magnusson <[email protected]> Tested-by: Ulf Magnusson <[email protected]> Signed-off-by: Michal Marek <[email protected]>
1 parent 35ffd08 commit c226456

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

scripts/kconfig/zconf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ comment, T_COMMENT, TF_COMMAND
2222
config, T_CONFIG, TF_COMMAND
2323
menuconfig, T_MENUCONFIG, TF_COMMAND
2424
help, T_HELP, TF_COMMAND
25+
---help---, T_HELP, TF_COMMAND
2526
if, T_IF, TF_COMMAND|TF_PARAM
2627
endif, T_ENDIF, TF_COMMAND
2728
depends, T_DEPENDS, TF_COMMAND

scripts/kconfig/zconf.l

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ static void alloc_string(const char *str, int size)
6666
memcpy(text, str, size);
6767
text[size] = 0;
6868
}
69+
70+
static void warn_ignored_character(char chr)
71+
{
72+
fprintf(stderr,
73+
"%s:%d:warning: ignoring unsupported character '%c'\n",
74+
zconf_curname(), zconf_lineno(), chr);
75+
}
6976
%}
7077

71-
n [A-Za-z0-9_]
78+
n [A-Za-z0-9_-]
7279

7380
%%
7481
int str = 0;
@@ -106,7 +113,7 @@ n [A-Za-z0-9_]
106113
zconflval.string = text;
107114
return T_WORD;
108115
}
109-
.
116+
. warn_ignored_character(*yytext);
110117
\n {
111118
BEGIN(INITIAL);
112119
current_file->lineno++;
@@ -132,8 +139,7 @@ n [A-Za-z0-9_]
132139
BEGIN(STRING);
133140
}
134141
\n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
135-
--- /* ignore */
136-
({n}|[-/.])+ {
142+
({n}|[/.])+ {
137143
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
138144
if (id && id->flags & TF_PARAM) {
139145
zconflval.id = id;
@@ -146,11 +152,7 @@ n [A-Za-z0-9_]
146152
#.* /* comment */
147153
\\\n current_file->lineno++;
148154
[[:blank:]]+
149-
. {
150-
fprintf(stderr,
151-
"%s:%d:warning: ignoring unsupported character '%c'\n",
152-
zconf_curname(), zconf_lineno(), *yytext);
153-
}
155+
. warn_ignored_character(*yytext);
154156
<<EOF>> {
155157
BEGIN(INITIAL);
156158
}

0 commit comments

Comments
 (0)