From 9ab051bdda8de83df9abbaf00e76500875c3669e Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Thu, 8 Aug 2019 11:56:18 +0000 Subject: [clang-format] fix crash involving invalid preprocessor line Summary: This (invalid) fragment is crashing clang-format: ``` #if 1 int x; #elif int y; #endif ``` The reason being that the parser expects a token after `#elif`, and the subsequent parsing of the next line does not check if `CurrentToken` is null. Reviewers: gribozavr Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65940 llvm-svn: 368280 --- clang/lib/Format/TokenAnnotator.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'clang/lib/Format') diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6e0369f27e7..cc0a954dbfb 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1099,6 +1099,8 @@ private: public: LineType parseLine() { + if (!CurrentToken) + return LT_Invalid; NonTemplateLess.clear(); if (CurrentToken->is(tok::hash)) return parsePreprocessorDirective(); -- cgit v1.2.3