[flang-commits] [flang] [flang][unittests] Fix buffer overrun in FrontendActionTest (PR #84381)
via flang-commits
flang-commits at lists.llvm.org
Thu Mar 7 13:34:18 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/84381.diff
1 Files Affected:
- (modified) flang/unittests/Frontend/FrontendActionTest.cpp (+3-2)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/84381
More information about the flang-commits
mailing list