Avoid undefined behavior when nullptr is passed to memcpy with size 0
This commit is contained in:
parent
ce65f5ac3c
commit
27c30ec671
2 changed files with 25 additions and 5 deletions
|
|
@ -408,6 +408,20 @@ TEST(StrCat, VectorBoolReferenceTypes) {
|
|||
EXPECT_EQ(result, "1010");
|
||||
}
|
||||
|
||||
// Passing nullptr to memcpy is undefined behavior and this test
|
||||
// provides coverage of codepaths that handle empty strings with nullptrs.
|
||||
TEST(StrCat, AvoidsMemcpyWithNullptr) {
|
||||
EXPECT_EQ(absl::StrCat(42, absl::string_view{}), "42");
|
||||
|
||||
// Cover CatPieces code.
|
||||
EXPECT_EQ(absl::StrCat(1, 2, 3, 4, 5, absl::string_view{}), "12345");
|
||||
|
||||
// Cover AppendPieces.
|
||||
std::string result;
|
||||
absl::StrAppend(&result, 1, 2, 3, 4, 5, absl::string_view{});
|
||||
EXPECT_EQ(result, "12345");
|
||||
}
|
||||
|
||||
#ifdef GTEST_HAS_DEATH_TEST
|
||||
TEST(StrAppend, Death) {
|
||||
std::string s = "self";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue