Commit e92505d8 by Dino Radakovic Committed by Copybara-Service

Use NullSafeStringView for const char* args to absl::StrCat, treating null pointers as ""

Fixes #1167

PiperOrigin-RevId: 449328725
Change-Id: I813785db77b94efa49eeeff4c93449334c380935
parent 7d3b4c86
...@@ -251,7 +251,8 @@ class AlphaNum { ...@@ -251,7 +251,8 @@ class AlphaNum {
const strings_internal::AlphaNumBuffer<size>& buf) const strings_internal::AlphaNumBuffer<size>& buf)
: piece_(&buf.data[0], buf.size) {} : piece_(&buf.data[0], buf.size) {}
AlphaNum(const char* c_str) : piece_(c_str) {} // NOLINT(runtime/explicit) AlphaNum(const char* c_str) // NOLINT(runtime/explicit)
: piece_(NullSafeStringView(c_str)) {} // NOLINT(runtime/explicit)
AlphaNum(absl::string_view pc) : piece_(pc) {} // NOLINT(runtime/explicit) AlphaNum(absl::string_view pc) : piece_(pc) {} // NOLINT(runtime/explicit)
template <typename Allocator> template <typename Allocator>
......
...@@ -210,6 +210,11 @@ TEST(StrCat, CornerCases) { ...@@ -210,6 +210,11 @@ TEST(StrCat, CornerCases) {
EXPECT_EQ(result, ""); EXPECT_EQ(result, "");
} }
TEST(StrCat, NullConstCharPtr) {
const char* null = nullptr;
EXPECT_EQ(absl::StrCat("mon", null, "key"), "monkey");
}
// A minimal allocator that uses malloc(). // A minimal allocator that uses malloc().
template <typename T> template <typename T>
struct Mallocator { struct Mallocator {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment