File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
src/libraries/Common/src/System/Net Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -94,8 +94,11 @@ public SocketAddress(AddressFamily family, int size)
9494 InternalSize = size ;
9595#if ! SYSTEM_NET_PRIMITIVES_DLL && WINDOWS
9696 // WSARecvFrom needs a pinned pointer to the 32bit socket address size.
97- // Allocate extra bytes at the end of Buffer, so we don't need to pin anything else.
98- size += sizeof ( int ) ;
97+ // Allocate extra bytes at the end of Buffer with a 4-byte alignment, so we don't need to pin anything else.
98+ // The following forumla ensures addition of the minimum necessary extra padding,
99+ // eg. size=16 will be extended to 20, while size=17 will be extended to 24
100+ const int PtrSize = sizeof ( int ) ;
101+ size = ( size + PtrSize - 1 ) / PtrSize * PtrSize + PtrSize ;
99102#endif
100103 Buffer = new byte [ size ] ;
101104
You can’t perform that action at this time.
0 commit comments