Merge "Make operator= and constructor behavior consistent." am: ecfdacd86c am: 7e7e4a3860
am: b419030975
Change-Id: I7944ded56032b4e65aabb407349a54fe1450fdc1
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index 0612050..7add055 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -240,6 +240,11 @@
hidl_string &hidl_string::operator=(const char *s) {
clear();
+
+ if (s == nullptr) {
+ return *this;
+ }
+
copyFrom(s, strlen(s));
return *this;
}
diff --git a/test_main.cpp b/test_main.cpp
index 6bd7f83..4f59371 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -61,6 +61,8 @@
EXPECT_STREQ(s2.c_str(), "s2");
hidl_string s2a(nullptr); // copy constructor from null cstr
EXPECT_STREQ("", s2a);
+ s2a = nullptr; // = from nullptr cstr
+ EXPECT_STREQ(s2a.c_str(), "");
hidl_string s3 = hidl_string("s3"); // move =
EXPECT_STREQ(s3.c_str(), "s3");
hidl_string s4 = hidl_string("12345", 3); // copy constructor from cstr w/ length