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)
committerrubenwardy <rw@rubenwardy.com>
Fri, 22 Dec 2017 10:39:25 +0000 (10:39 +0000)
`&vector[0]` is undefined if vector.empty(), causing build failure on MSVC

src/network/networkpacket.cpp

index 14b1ac4401661df7476bd5df91e371aa59744a1e..530f0fe707bd2b7e8083fefc280f675c34d4b9cd 100644 (file)
@@ -63,7 +63,7 @@ void NetworkPacket::putRawPacket(u8 *data, u32 datasize, session_t 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)