From 909ab54575c0f8354bd2aa8bcffa75ed6e1eb93a Mon Sep 17 00:00:00 2001 From: Pawel Wasowski Date: Mon, 18 Jan 2021 22:11:55 +0100 Subject: [PATCH] [mediacontroller] Prevent undefined behavior 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 --- src/mediacontroller/mediacontroller_client.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mediacontroller/mediacontroller_client.cc b/src/mediacontroller/mediacontroller_client.cc index 6ff85f5f..82d927d7 100644 --- a/src/mediacontroller/mediacontroller_client.cc +++ b/src/mediacontroller/mediacontroller_client.cc @@ -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); -- 2.34.1