diff options
| author | Dmitri Gribenko <gribozavr@gmail.com> | 2013-09-27 21:24:36 +0000 |
|---|---|---|
| committer | Dmitri Gribenko <gribozavr@gmail.com> | 2013-09-27 21:24:36 +0000 |
| commit | 78fe2ba3ba92c25b4b1ae42027081af16f0ddf06 (patch) | |
| tree | fbd5beb795fa828e3335d6203b500f91531ba611 | |
| parent | 30e9b6c47d8891b68f8cea1125987e4a0b8b6a82 (diff) | |
| download | bcm5719-llvm-78fe2ba3ba92c25b4b1ae42027081af16f0ddf06.tar.gz bcm5719-llvm-78fe2ba3ba92c25b4b1ae42027081af16f0ddf06.zip | |
SourceMgr diagnotics printing: fix a bug where printing a fixit for a source
range that includes a tab character will cause out-of-bounds access to the
fixit string.
llvm-svn: 191563
| -rw-r--r-- | llvm/lib/Support/SourceMgr.cpp | 2 | ||||
| -rw-r--r-- | llvm/unittests/Support/SourceMgrTest.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp index fbcd8f980c1..d4b94f8cd5d 100644 --- a/llvm/lib/Support/SourceMgr.cpp +++ b/llvm/lib/Support/SourceMgr.cpp @@ -470,7 +470,7 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S, if (FixItInsertionLine.empty()) return; - for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i != e; ++i) { + for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) { if (i >= LineContents.size() || LineContents[i] != '\t') { S << FixItInsertionLine[i]; ++OutCol; diff --git a/llvm/unittests/Support/SourceMgrTest.cpp b/llvm/unittests/Support/SourceMgrTest.cpp index 9bc0cf67b75..2b69fe98444 100644 --- a/llvm/unittests/Support/SourceMgrTest.cpp +++ b/llvm/unittests/Support/SourceMgrTest.cpp @@ -160,3 +160,15 @@ TEST_F(SourceMgrTest, BasicFixit) { Output); } +TEST_F(SourceMgrTest, FixitForTab) { + setMainBuffer("aaa\tbbb\nccc ddd\n", "file.in"); + printMessage(getLoc(3), SourceMgr::DK_Error, "message", None, + makeArrayRef(SMFixIt(getRange(3, 1), "zzz"))); + + EXPECT_EQ("file.in:1:4: error: message\n" + "aaa bbb\n" + " ^^^^^\n" + " zzz\n", + Output); +} + |

