Skip to content

Commit

Permalink
[flang][unittests] Fix buffer overrun in FrontendActionTest (#84381)
Browse files Browse the repository at this point in the history
When` SmallVector<char>` is used as a backing storage, it can't be
assumed to end with a \x0. When creating a `StringRef` from it, pass the
length explicitly.

This was detected by address sanitizer.
  • Loading branch information
kparzysz committed Mar 8, 2024
1 parent 65524fc commit aa26faf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flang/unittests/Frontend/FrontendActionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ TEST_F(FrontendActionTest, EmitLLVM) {
EXPECT_TRUE(success);
EXPECT_TRUE(!outputFileBuffer.empty());

EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data())
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.begin(), outputFileBuffer.size())
.contains("define void @_QQmain()"));
}

Expand Down Expand Up @@ -227,6 +227,7 @@ TEST_F(FrontendActionTest, EmitAsm) {
EXPECT_TRUE(success);
EXPECT_TRUE(!outputFileBuffer.empty());

EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data()).contains("_QQmain"));
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.begin(), outputFileBuffer.size())
.contains("_QQmain"));
}
} // namespace

0 comments on commit aa26faf

Please sign in to comment.