From: Hongkuk, Son Date: Mon, 10 Apr 2017 09:21:18 +0000 (+0900) Subject: Fix to assign string.Empty when Marshal.PtrToStringAnsi(XXXptr)'s XXXptr is IntPtr... X-Git-Tag: submit/trunk/20170823.075128~105^2~9^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fcbbf0f3ff9a54b4d0f41616b9904cd11aead6dd;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Fix to assign string.Empty when Marshal.PtrToStringAnsi(XXXptr)'s XXXptr is IntPtr.Zero Signed-off-by: Hongkuk, Son Change-Id: I757e7f4e04fc5a42fbb04fb03dd238f9ac28f72c --- diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs index 57a6e3a..7514598 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs @@ -546,7 +546,7 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } - Str = Marshal.PtrToStringAnsi(value); + Str = (value != IntPtr.Zero) ? Marshal.PtrToStringAnsi(value) : string.Empty; _attributes.Add(key, Str); break; } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs index 066d8ce..5c057bd 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs @@ -753,8 +753,8 @@ namespace Tizen.Network.IoTConnectivity PresenceReceivedEventArgs e = new PresenceReceivedEventArgs() { PresenceId = presenceId, - HostAddress = Marshal.PtrToStringAnsi(host), - Type = Marshal.PtrToStringAnsi(type), + HostAddress = (host != IntPtr.Zero) ? Marshal.PtrToStringAnsi(host) : string.Empty, + Type = (type != IntPtr.Zero) ? Marshal.PtrToStringAnsi(type) : string.Empty, EventType = (PresenceEventType)trigger }; @@ -797,10 +797,10 @@ namespace Tizen.Network.IoTConnectivity { RequestId = requestId, EventContinue = true, - Name = Marshal.PtrToStringAnsi(name), - SpecVersion = Marshal.PtrToStringAnsi(specVersion), - DeviceId = Marshal.PtrToStringAnsi(deviceId), - DataModelVersion = Marshal.PtrToStringAnsi(dataModelVersion) + Name = (name != IntPtr.Zero) ? Marshal.PtrToStringAnsi(name) : string.Empty, + SpecVersion = (specVersion != IntPtr.Zero) ? Marshal.PtrToStringAnsi(specVersion) : string.Empty, + DeviceId = (deviceId != IntPtr.Zero) ? Marshal.PtrToStringAnsi(deviceId) : string.Empty, + DataModelVersion = (dataModelVersion != IntPtr.Zero) ? Marshal.PtrToStringAnsi(dataModelVersion) : string.Empty }; return e; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs index ca57ffc..77c5c71 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs @@ -805,9 +805,9 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device id"); throw IoTConnectivityErrorFactory.GetException(ret); } - DeviceId = Marshal.PtrToStringAnsi(deviceIdPtr); - HostAddress = Marshal.PtrToStringAnsi(hostAddressPtr); - UriPath = Marshal.PtrToStringAnsi(uriPathPtr); + DeviceId = (deviceIdPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(deviceIdPtr) : string.Empty; + HostAddress = (hostAddressPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(hostAddressPtr) : string.Empty; + UriPath = (uriPathPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(uriPathPtr) : string.Empty; Types = new ResourceTypes(typesHandle); Interfaces = new ResourceInterfaces(interfacesHandle); Policy = (ResourcePolicy)policy; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs index 81e6fbc..67a0eb2 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs @@ -105,7 +105,7 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get uri"); throw IoTConnectivityErrorFactory.GetException(ret); } - return Marshal.PtrToStringAnsi(path); + return (path != IntPtr.Zero) ? Marshal.PtrToStringAnsi(path) : string.Empty; } set { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs index f2dbb8d..39b189e 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs @@ -448,7 +448,7 @@ namespace Tizen.Network.IoTConnectivity return new Request() { - HostAddress = Marshal.PtrToStringAnsi(hostAddressPtr), + HostAddress = (hostAddressPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(hostAddressPtr) : string.Empty, Options = opts, Query = query, Representation = representation diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs index ecbc672..54153d0 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs @@ -106,7 +106,7 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type"); return ""; } - return Marshal.PtrToStringAnsi(type); + return (type != IntPtr.Zero) ? Marshal.PtrToStringAnsi(type) : string.Empty; } set { @@ -146,7 +146,7 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get interface"); return ""; } - return Marshal.PtrToStringAnsi(iface); + return (iface != IntPtr.Zero) ? Marshal.PtrToStringAnsi(iface) : string.Empty; } set {