Skip to content

Commit

Permalink
add 4-byte alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed Nov 30, 2022
1 parent 7392b08 commit ddb50fc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/libraries/Common/src/System/Net/SocketAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public SocketAddress(AddressFamily family, int size)
InternalSize = size;
#if !SYSTEM_NET_PRIMITIVES_DLL && WINDOWS
// WSARecvFrom needs a pinned pointer to the 32bit socket address size.
// Allocate extra bytes at the end of Buffer, so we don't need to pin anything else.
size += sizeof(int);
// Allocate extra bytes at the end of Buffer with a 4-byte alignment, so we don't need to pin anything else.
// The following forumla ensures addition of the minimum necessary extra padding,
// eg. size=16 will be extended to 20, while size=17 will be extended to 24
const int PtrSize = sizeof(int);
size = (size + PtrSize - 1) / PtrSize * PtrSize + PtrSize;
#endif
Buffer = new byte[size];

Expand Down

0 comments on commit ddb50fc

Please sign in to comment.