Skip to content

Commit

Permalink
Fix strndup
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 authored and ForNeVeR committed Sep 14, 2024
1 parent 2498e5e commit 7735ae6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cesium.Runtime/StringFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,17 @@ 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)
{
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;
}
}

0 comments on commit 7735ae6

Please sign in to comment.