]> granicus.if.org Git - clang/commitdiff
Fix possible OOB access found by buildbot
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 9 Feb 2016 11:01:58 +0000 (11:01 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 9 Feb 2016 11:01:58 +0000 (11:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260219 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrintPreprocessedOutput.cpp

index c57a736d1b0449aa374c5f4b3d84669bd63298cd..eee9da8594bbc98fcefb9cf501c1b60ca6cc2a20 100644 (file)
@@ -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();