[llvm] r191563 - SourceMgr diagnotics printing: fix a bug where printing a fixit for a source
Dmitri Gribenko
gribozavr at gmail.com
Fri Sep 27 14:24:36 PDT 2013
Author: gribozavr
Date: Fri Sep 27 16:24:36 2013
New Revision: 191563
URL: http://llvm.org/viewvc/llvm-project?rev=191563&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Support/SourceMgr.cpp
llvm/trunk/unittests/Support/SourceMgrTest.cpp
Modified: llvm/trunk/lib/Support/SourceMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SourceMgr.cpp?rev=191563&r1=191562&r2=191563&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SourceMgr.cpp (original)
+++ llvm/trunk/lib/Support/SourceMgr.cpp Fri Sep 27 16:24:36 2013
@@ -470,7 +470,7 @@ void SMDiagnostic::print(const char *Pro
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;
Modified: llvm/trunk/unittests/Support/SourceMgrTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/SourceMgrTest.cpp?rev=191563&r1=191562&r2=191563&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/SourceMgrTest.cpp (original)
+++ llvm/trunk/unittests/Support/SourceMgrTest.cpp Fri Sep 27 16:24:36 2013
@@ -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);
+}
+
More information about the llvm-commits
mailing list