1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

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
This commit is contained in:
Dmitri Gribenko 2013-09-27 21:24:36 +00:00
parent 885b54ffc7
commit 9c747f2fbc
2 changed files with 13 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}