[mediacontroller] Prevent undefined behavior 25/251825/3
authorPawel Wasowski <p.wasowski2@samsung.com>
Mon, 18 Jan 2021 21:11:55 +0000 (22:11 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Tue, 19 Jan 2021 14:57:07 +0000 (14:57 +0000)
Constructing a std::string from nullptr is undefined behavior and
caused an exception after setting std=c++17 flag in GCC
(no exception was thrown when compiling with std=c++14).
This commit removes the UB.

The problem caused MediaControllerServerInfo_iconURI_attribute test
from tct-mediacontroller-tizen-tests failures.

[Verification] auto tct-mediacontroller-tizen-tests
1. with std=c++14: 100% pass rate
2. with std=c++17: 100% pass rate

Change-Id: I4857e3d9f8ba2940b50223e89ff952625ba37b3c
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/mediacontroller/mediacontroller_client.cc

index 6ff85f5ff16044fef2ebbf2dac7377e736a16a6e..82d927d739edb0540e2b5fd874ab686b192b2509 100644 (file)
@@ -554,9 +554,10 @@ PlatformResult MediaControllerClient::GetServerIconURI(const std::string& name,
     return PlatformResult(ErrorCode::UNKNOWN_ERR);
   }
 
-  *icon_uri = nullptr;
   if (nullptr != icon_uri_str) {
     *icon_uri = std::string(icon_uri_str);
+  } else {
+    *icon_uri = std::string{};
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);