[flang-commits] [flang] [flang][unittests] Fix buffer overrun in FrontendActionTest (PR #84381)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Thu Mar 7 13:33:46 PST 2024
https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/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.
>From 6a6193e2b8d40f46ce73782a942425e70b3f86e3 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 7 Mar 2024 15:31:03 -0600
Subject: [PATCH] [flang][unittests] Fix buffer overrun in FrontendActionTest
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.
---
flang/unittests/Frontend/FrontendActionTest.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
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