Fix missing null-termination in D2D entry points

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-15 15:01:18 +02:00
1 親 1a3040060e
コミット 9e0eeeedca
1ファイル変更
+5 -2
+5 -2
ファイルの表示
@@ -37,10 +37,13 @@ public static class D2D1ShaderCompiler
int sourceWrittenBytes = Encoding.ASCII.GetBytes(hlslSource, sourceBuffer);
// Encode the entry point to ASCII
int maxEntryPointLength = Encoding.ASCII.GetMaxByteCount(entryPoint.Length);
int maxEntryPointLength = Encoding.ASCII.GetMaxByteCount(entryPoint.Length) + 1;
byte[] entryPointBuffer = ArrayPool<byte>.Shared.Rent(maxEntryPointLength);
int entryPointWrittenBytes = Encoding.ASCII.GetBytes(entryPoint, entryPointBuffer);
// The entry point has to be null-terminated
entryPointBuffer[entryPointWrittenBytes] = (byte)'\0';
ReadOnlySpan<byte> sourceAscii = sourceBuffer.AsSpan(0, sourceWrittenBytes);
ReadOnlySpan<byte> entryPointAscii = entryPointBuffer.AsSpan(0, entryPointWrittenBytes);
@@ -56,7 +59,7 @@ public static class D2D1ShaderCompiler
/// Compiles a new HLSL shader from the input source code.
/// </summary>
/// <param name="hlslSourceAscii">The HLSL source code to compile (in ASCII).</param>
/// <param name="entryPointAscii">The entry point of the shader being compiled (in ASCII).</param>
/// <param name="entryPointAscii">The entry point of the shader being compiled (in ASCII, null-terminated).</param>
/// <param name="shaderProfile">The shader profile to use to compile the shader.</param>
/// <param name="options">The compiler options to use to compile the shader.</param>
/// <returns>The bytecode for the compiled shader.</returns>