From 77cffe2f92b908fc9d14041139b689caba365e34 Mon Sep 17 00:00:00 2001 From: Keith Holman Date: Mon, 15 Jan 2018 11:06:03 -0800 Subject: [PATCH] When a null C# string is passed to UTF8_ToNative(), return a null pointer instead of an empty C string. --- src/SDL2.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index 1b64646..cfbf245 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -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)