Fix undefined behaviour on getting pointer to data in empty vector
authornOOb3167 <nOOb3167@gmail.com>
Fri, 22 Dec 2017 10:33:46 +0000 (11:33 +0100)
committerSmallJoker <mk939@ymail.com>
Sun, 3 Jun 2018 15:32:00 +0000 (17:32 +0200)
`&vector[0]` is undefined if vector.empty(), causing build failure on MSVC

src/network/networkpacket.cpp

index 8e06ae104a6c6957c3d9ea7ec82ce46ba4d192e0..c4fcf9600d2cb76977bbc20ab5ca4e6e19894c02 100644 (file)
@@ -62,7 +62,7 @@ void NetworkPacket::putRawPacket(u8 *data, u32 datasize, u16 peer_id)
 
        // split command and datas
        m_command = readU16(&data[0]);
-       memcpy(&m_data[0], &data[2], m_datasize);
+       memcpy(m_data.data(), &data[2], m_datasize);
 }
 
 const char* NetworkPacket::getString(u32 from_offset)