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

This commit is contained in:
Keith Holman 2018-01-15 11:06:03 -08:00 committed by Ethan Lee
parent ed4838b75d
commit 77cffe2f92

View file

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