From: Guilherme Maciel Ferreira Date: Sun, 4 Sep 2011 11:59:20 +0000 (-0300) Subject: Implementing the assignment operator, also checking for self-assignment reported... X-Git-Tag: v1.2~61 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=08ec02d5973400b3046b431e68bae34f3ab345bc;p=pingcheck Implementing the assignment operator, also checking for self-assignment reported by PC-lint - Warning 1529: Symbol 'MessagePayload::operator=(const MessagePayload &)' not first checking for assignment to this - Warning 1539: member 'MessagePayload::PayloadSizeInBytes' not assigned by assignment operator - Warning 1539: member 'MessagePayload::Payload' not assigned by assignment operator --- diff --git a/src/host/messagepayload.cpp b/src/host/messagepayload.cpp index 801a9f8..4d10a1b 100644 --- a/src/host/messagepayload.cpp +++ b/src/host/messagepayload.cpp @@ -76,9 +76,17 @@ MessagePayload& MessagePayload::operator=( const MessagePayload &other ) BOOST_ASSERT( Payload.get() != NULL ); BOOST_ASSERT( other.Payload.get() != NULL ); - // FIXME must resize the Payload in order to work + // checking for self-assignment (i.e. object1 = object1) + if ( &other == this ) { + return *this; + } - copy( other.Payload.get(), other.Payload.get() + PayloadSizeInBytes, Payload.get() ); + size_t new_payload_size_in_bytes = other.PayloadSizeInBytes; + uint8_t *new_payload_data = new uint8_t[ new_payload_size_in_bytes ]; + Payload.reset( new_payload_data ); + PayloadSizeInBytes = new_payload_size_in_bytes; + + copy( other.Payload.get(), other.Payload.get() + other.PayloadSizeInBytes, Payload.get() ); BOOST_ASSERT( PayloadSizeInBytes == other.PayloadSizeInBytes );