Skip to content

Commit 60cf079

Browse files
committed
Make sure we don't crash when we get a null string
1 parent daddc4a commit 60cf079

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

GLFW.NET/Util.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ internal static class Util
1919
// ReSharper disable once InconsistentNaming
2020
public static string PtrToStringUTF8(IntPtr ptr)
2121
{
22-
var length = 0;
23-
while (Marshal.ReadByte(ptr, length) != 0)
24-
length++;
25-
var buffer = new byte[length];
26-
Marshal.Copy(ptr, buffer, 0, length);
27-
return Encoding.UTF8.GetString(buffer);
22+
if (ptr != IntPtr.Zero)
23+
{
24+
var length = 0;
25+
while (Marshal.ReadByte(ptr, length) != 0)
26+
length++;
27+
var buffer = new byte[length];
28+
Marshal.Copy(ptr, buffer, 0, length);
29+
return Encoding.UTF8.GetString(buffer);
30+
}
31+
32+
return "";
2833
}
2934

3035
#endregion

0 commit comments

Comments
 (0)