Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pycparser/c_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ def success(pp_line: Optional[str], pp_filename: Optional[str]) -> None:
if pp_line is None:
self._error("line number missing in #line", self._pos + line_len)
else:
self._lineno = int(pp_line)
try:
self._lineno = int(pp_line)
except ValueError:
self._error("invalid #line directive", self._pos + line_len)
return
if pp_filename is not None:
self._filename = pp_filename
self._pos = line_end + 1
Expand Down
4 changes: 4 additions & 0 deletions tests/test_c_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ def test_preprocessor(self):
self.assertLexerError('#line "ka"', ERR_FILENAME_BEFORE_LINE)
self.assertLexerError("#line df", ERR_INVALID_LINE_DIRECTIVE)
self.assertLexerError("#line \n", ERR_LINENUM_MISSING)
# Integer suffixes are not valid in #line directives (issue #587).
self.assertLexerError("#line 0u", ERR_INVALID_LINE_DIRECTIVE)
self.assertLexerError("#line 1U", ERR_INVALID_LINE_DIRECTIVE)
self.assertLexerError("#line 10uLL", ERR_INVALID_LINE_DIRECTIVE)
# a compatible preprocessor must remove comments.
self.assertLexerError("//", ERR_COMMENT)
self.assertLexerError("/*", ERR_COMMENT)
Expand Down
Loading