When a null C# string is passed to UTF8_ToNative(), return a null pointer instead of an empty C string.

master
Keith Holman 2018-01-15 11:06:03 -08:00 committed by Ethan Lee
parent ed4838b75d
commit 77cffe2f92
1 changed files with 9 additions and 2 deletions

View File

@ -45,8 +45,15 @@ namespace SDL2
internal static byte[] UTF8_ToNative(string s)
{
// Add a null terminator. That's kind of it... :/
return System.Text.Encoding.UTF8.GetBytes(s + '\0');
if (s != null)
{
// Add a null terminator. That's kind of it... :/
return System.Text.Encoding.UTF8.GetBytes(s + '\0');
}
else
{
return null;
}
}
internal static unsafe string UTF8_ToManaged(IntPtr s, bool freePtr = false)