From: Alexey Bataev Date: Tue, 9 Feb 2016 11:01:58 +0000 (+0000) Subject: Fix possible OOB access found by buildbot X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de6b5ce21f37f06fa061217d426f44176bfc7184;p=clang Fix possible OOB access found by buildbot git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260219 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index c57a736d1b..eee9da8594 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -573,19 +573,20 @@ struct UnknownPragmaHandler : public PragmaHandler { Token &PragmaTok) override { // Figure out what line we went to and insert the appropriate number of // newline characters. + Callbacks->startNewLineIfNeeded(); + Callbacks->MoveToLine(PragmaTok.getLocation()); + Callbacks->OS.write(Prefix, strlen(Prefix)); + if (ShouldExpandTokens) { // The first token does not have expanded macros. Expand them, if // required. - Token Toks[] = {PragmaTok}; - PP.EnterTokenStream(Toks, llvm::array_lengthof(Toks), + Token *Toks = new Token[1]; + Toks[0] = PragmaTok; + PP.EnterTokenStream(Toks, /*NumToks=*/1, /*DisableMacroExpansion=*/false, - /*OwnsTokens=*/false); + /*OwnsTokens=*/true); PP.Lex(PragmaTok); } - Callbacks->startNewLineIfNeeded(); - Callbacks->MoveToLine(PragmaTok.getLocation()); - Callbacks->OS.write(Prefix, strlen(Prefix)); - Token PrevToken; Token PrevPrevToken; PrevToken.startToken();