From eda9214f81b32d9606f425e3777616e8cfc0a44f Mon Sep 17 00:00:00 2001 From: sapier Date: Sun, 6 Apr 2014 15:12:04 +0200 Subject: Bunch of small fixes (coding style, very unlikely errors, warning messages) --- src/connection.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/connection.cpp') diff --git a/src/connection.cpp b/src/connection.cpp index 32634ac89..ae1e4a1db 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -111,10 +111,10 @@ SharedBuffer makeOriginalPacket( u32 packet_size = data.getSize() + header_size; SharedBuffer b(packet_size); - writeU8(&b[0], TYPE_ORIGINAL); - - memcpy(&b[header_size], *data, data.getSize()); - + writeU8(&(b[0]), TYPE_ORIGINAL); + if (data.getSize() > 0) { + memcpy(&(b[header_size]), *data, data.getSize()); + } return b; } @@ -2266,14 +2266,14 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, if(packetdata.getSize() < 1) throw InvalidIncomingDataException("packetdata.getSize() < 1"); - u8 type = readU8(&packetdata[0]); + u8 type = readU8(&(packetdata[0])); if(type == TYPE_CONTROL) { if(packetdata.getSize() < 2) throw InvalidIncomingDataException("packetdata.getSize() < 2"); - u8 controltype = readU8(&packetdata[1]); + u8 controltype = readU8(&(packetdata[1])); if( (controltype == CONTROLTYPE_ACK) && (peer_id <= MAX_UDP_PEERS)) @@ -2398,15 +2398,15 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, } else if(type == TYPE_ORIGINAL) { - if(packetdata.getSize() < ORIGINAL_HEADER_SIZE) + if(packetdata.getSize() <= ORIGINAL_HEADER_SIZE) throw InvalidIncomingDataException - ("packetdata.getSize() < ORIGINAL_HEADER_SIZE"); + ("packetdata.getSize() <= ORIGINAL_HEADER_SIZE"); LOG(dout_con<getDesc() <<"RETURNING TYPE_ORIGINAL to user" < payload(packetdata.getSize() - ORIGINAL_HEADER_SIZE); - memcpy(*payload, &packetdata[ORIGINAL_HEADER_SIZE], payload.getSize()); + memcpy(*payload, &(packetdata[ORIGINAL_HEADER_SIZE]), payload.getSize()); return payload; } else if(type == TYPE_SPLIT) -- cgit v1.2.3