diff options
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/MarshalUtils.cs')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/MarshalUtils.cs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/csharp/Grpc.Core/Internal/MarshalUtils.cs b/src/csharp/Grpc.Core/Internal/MarshalUtils.cs index 3f9605bfdd..09ded1a036 100644 --- a/src/csharp/Grpc.Core/Internal/MarshalUtils.cs +++ b/src/csharp/Grpc.Core/Internal/MarshalUtils.cs @@ -35,6 +35,13 @@ namespace Grpc.Core.Internal /// </summary> public static string PtrToStringUTF8(IntPtr ptr, int len) { + if (len == 0) + { + return ""; + } + + // TODO(jtattermusch): once Span dependency is added, + // use Span-based API to decode the string without copying the buffer. var bytes = new byte[len]; Marshal.Copy(ptr, bytes, 0, len); return EncodingUTF8.GetString(bytes); |