[flang-commits] [flang] aa26faf - [flang][unittests] Fix buffer overrun in FrontendActionTest (#84381)
via flang-commits
flang-commits at lists.llvm.org
Fri Mar 8 05:21:24 PST 2024
Author: Krzysztof Parzyszek
Date: 2024-03-08T07:21:21-06:00
New Revision: aa26faf05ecd7ee77487772fe0406f2de1df0dac
URL: https://github.com/llvm/llvm-project/commit/aa26faf05ecd7ee77487772fe0406f2de1df0dac
DIFF: https://github.com/llvm/llvm-project/commit/aa26faf05ecd7ee77487772fe0406f2de1df0dac.diff
LOG: [flang][unittests] Fix buffer overrun in FrontendActionTest (#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.
Added:
Modified:
flang/unittests/Frontend/FrontendActionTest.cpp
Removed:
################################################################################
diff --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp
index 6ec15832d96d3c..123f428cc8b40b 100644
--- a/flang/unittests/Frontend/FrontendActionTest.cpp
+++ b/flang/unittests/Frontend/FrontendActionTest.cpp
@@ -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()"));
}
@@ -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
More information about the flang-commits
mailing list