Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal void AddArray(Array? value, int length, int itemSize)
length = ushort.MaxValue;
}

int size = length * itemSize;
int size = checked(length * itemSize);
if (this.bufferNesting != 0)
{
this.EnsureBuffer(size + 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void Encode(ref int pos, byte[]? metadata)
if (metadata != null)
{
Debug.Assert(custom != null);
Debug.Assert(checked(pos + this.fixedCount) <= metadata.Length);
Buffer.BlockCopy(custom, 0, metadata, pos, this.fixedCount);
}
pos += this.fixedCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ internal static unsafe void Copy(UnmanagedBuffer source, UnmanagedBuffer destina
return;
}

Debug.Assert(bytesLength <= destination.ByteLength);

byte* srcPtr = null, dstPtr = null;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,23 @@ public static async Task<JSObject> CancellationHelper(Task<JSObject> jsTask, Can
public static unsafe JSFunctionBinding GetMethodSignature(ReadOnlySpan<JSMarshalerType> types, string? functionName, string? moduleName)
{
int argsCount = types.Length - 1;
int size = JSFunctionBinding.JSBindingHeader.JSMarshalerSignatureHeaderSize + ((argsCount + 2) * sizeof(JSFunctionBinding.JSBindingType));
int size = checked(JSFunctionBinding.JSBindingHeader.JSMarshalerSignatureHeaderSize + ((argsCount + 2) * sizeof(JSFunctionBinding.JSBindingType)));

int functionNameBytes = 0;
int functionNameOffset = 0;
if (functionName != null)
{
functionNameOffset = size;
size += 4;
functionNameBytes = functionName.Length * 2;
size += functionNameBytes;
functionNameBytes = checked(functionName.Length * 2);
size = checked(size + 4 + functionNameBytes);
}
int moduleNameBytes = 0;
int moduleNameOffset = 0;
if (moduleName != null)
{
moduleNameOffset = size;
size += 4;
moduleNameBytes = moduleName.Length * 2;
size += moduleNameBytes;
moduleNameBytes = checked(moduleName.Length * 2);
size = checked(size + 4 + moduleNameBytes);
}

// this is never unallocated
Expand Down
Loading