diff --git a/Cesium.Runtime/StringFunctions.cs b/Cesium.Runtime/StringFunctions.cs index 60d793d7..a0f6fb1a 100644 --- a/Cesium.Runtime/StringFunctions.cs +++ b/Cesium.Runtime/StringFunctions.cs @@ -196,7 +196,7 @@ public static int MemCmp(void* lhs, void* rhs, nuint count) public static UTF8String StrDup(UTF8String src) { - return StrNDup(src, src.Length + 1); + return StrNDup(src, src.Length); } public static UTF8String StrNDup(UTF8String src, nuint count) @@ -204,8 +204,9 @@ public static UTF8String StrNDup(UTF8String src, nuint count) if (src.Pointer == null) return UTF8String.NullString; - var dest = new UTF8String((byte*)StdLibFunctions.Malloc(count)); + var dest = new UTF8String((byte*)StdLibFunctions.Malloc(count + 1)); src.CopyTo(dest, count); + dest[count] = 0; return dest; } }