Merge "Make operator= and constructor behavior consistent."
am: ecfdacd86c

Change-Id: I46d6336cf061cdeb726c19c6b3fe4e730c437429
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index ec5b18f..6f04838 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -239,6 +239,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