Author: sstwcw Date: 2022-06-26T22:23:50Z New Revision: 141ad3ba05711cc8396a34fce6b26648d216eb8e
URL: https://github.com/llvm/llvm-project/commit/141ad3ba05711cc8396a34fce6b26648d216eb8e DIFF: https://github.com/llvm/llvm-project/commit/141ad3ba05711cc8396a34fce6b26648d216eb8e.diff LOG: [clang-format] Fix uninitialized memory problem The setLength function checks for the token kind which could be uninitialized in the previous version. The problem was introduced in 2e32ff106e. Reviewed By: MyDeveloperDay, owenpan Differential Revision: https://reviews.llvm.org/D128607 Added: Modified: clang/lib/Format/FormatTokenLexer.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index e3af9548b015..88b0d3b1970f 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -1128,11 +1128,12 @@ bool FormatTokenLexer::readRawTokenVerilogSpecific(Token &Tok) { return false; size_t Len = Matches[0].size(); - Tok.setLength(Len); - Tok.setLocation(Lex->getSourceLocation(Start, Len)); // The kind has to be an identifier so we can match it against those defined - // in Keywords. + // in Keywords. The kind has to be set before the length because the setLength + // function checks that the kind is not an annotation. Tok.setKind(tok::raw_identifier); + Tok.setLength(Len); + Tok.setLocation(Lex->getSourceLocation(Start, Len)); Tok.setRawIdentifierData(Start); Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false); return true; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits