Skip to content

Commit 5a7c2dd

Browse files
committed
SteamNetworkingIPAddr: fix potentially dangerous -wcast-align warning in IsIPv6AllZeroes()
C-style cast from `uint8*` to `uint64*` is unsafe and can blow up in cases when the source pointer is not aligned to `uint64` type requirements. Signed-off-by: Pavel Solodovnikov <[email protected]>
1 parent 6223714 commit 5a7c2dd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/steam/steamnetworkingtypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ typedef SteamNetworkingMessage_t ISteamNetworkingMessage;
18931893
typedef SteamNetworkingErrMsg SteamDatagramErrMsg;
18941894

18951895
inline void SteamNetworkingIPAddr::Clear() { memset( this, 0, sizeof(*this) ); }
1896-
inline bool SteamNetworkingIPAddr::IsIPv6AllZeros() const { const uint64 *q = (const uint64 *)m_ipv6; return q[0] == 0 && q[1] == 0; }
1896+
inline bool SteamNetworkingIPAddr::IsIPv6AllZeros() const { uint64 q[2] = {}; memcpy(q, m_ipv6, sizeof(m_ipv6)); return q[0] == 0 && q[1] == 0; }
18971897
inline void SteamNetworkingIPAddr::SetIPv6( const uint8 *ipv6, uint16 nPort ) { memcpy( m_ipv6, ipv6, 16 ); m_port = nPort; }
18981898
inline void SteamNetworkingIPAddr::SetIPv4( uint32 nIP, uint16 nPort ) { m_ipv4.m_8zeros = 0; m_ipv4.m_0000 = 0; m_ipv4.m_ffff = 0xffff; m_ipv4.m_ip[0] = uint8(nIP>>24); m_ipv4.m_ip[1] = uint8(nIP>>16); m_ipv4.m_ip[2] = uint8(nIP>>8); m_ipv4.m_ip[3] = uint8(nIP); m_port = nPort; }
18991899
inline bool SteamNetworkingIPAddr::IsIPv4() const { return m_ipv4.m_8zeros == 0 && m_ipv4.m_0000 == 0 && m_ipv4.m_ffff == 0xffff; }

0 commit comments

Comments
 (0)