Skip to content

Commit aa26faf

Browse files
authored
[flang][unittests] Fix buffer overrun in FrontendActionTest (llvm#84381)
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.
1 parent 65524fc commit aa26faf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

flang/unittests/Frontend/FrontendActionTest.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ TEST_F(FrontendActionTest, EmitLLVM) {
198198
EXPECT_TRUE(success);
199199
EXPECT_TRUE(!outputFileBuffer.empty());
200200

201-
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data())
201+
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.begin(), outputFileBuffer.size())
202202
.contains("define void @_QQmain()"));
203203
}
204204

@@ -227,6 +227,7 @@ TEST_F(FrontendActionTest, EmitAsm) {
227227
EXPECT_TRUE(success);
228228
EXPECT_TRUE(!outputFileBuffer.empty());
229229

230-
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data()).contains("_QQmain"));
230+
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.begin(), outputFileBuffer.size())
231+
.contains("_QQmain"));
231232
}
232233
} // namespace

0 commit comments

Comments
 (0)