[compiler-rt] [scudo] Add `__scudo_get_info` symbol to export stats to a buffer. (PR #130273)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 6 08:20:45 PDT 2025
================
@@ -128,6 +128,52 @@ TEST(ScudoStringsTest, Padding) {
testAgainstLibc<int>("%03d - %03d", -12, -1234);
}
+TEST(ScudoStringsTest, CopyIntoNullBuffer) {
+ scudo::ScopedString Str;
+ Str.append("abc");
+ EXPECT_EQ(4U, Str.copyToBuffer(nullptr, 0));
+}
+
+TEST(ScudoStringsTest, CopyFromAnEmptyString) {
+ scudo::ScopedString Str;
+ char buf[256] = {'0', '1'};
+ EXPECT_EQ(1U, Str.copyToBuffer(buf, sizeof(buf)));
+ EXPECT_STREQ("", buf);
+ EXPECT_EQ(0, buf[0]); // Rest of the buffer remains unchanged.
+}
+
+TEST(ScudoStringsTest, CopyFromAnEmptyStringIntoZeroSizeBuffer) {
+ scudo::ScopedString Str;
+ char buf[256] = {'0', '1'};
+ EXPECT_EQ(1U, Str.copyToBuffer(buf, 0));
+ EXPECT_EQ('0', buf[0]); // Nothing changed because provided size is 0.
+}
+
+TEST(ScudoStringsTest, CopyIntoLargeEnoughBuffer) {
+ scudo::ScopedString Str;
+ Str.append("abc");
+ char buf[256] = {'0', '1', '2', '3', '4', '5'};
----------------
piwicode wrote:
I forgot to check for overflow. Fixed.
https://github.com/llvm/llvm-project/pull/130273
More information about the llvm-commits
mailing list