From 08ec02d5973400b3046b431e68bae34f3ab345bc Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Sun, 4 Sep 2011 08:59:20 -0300 Subject: [PATCH] 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 --- src/host/messagepayload.cpp | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) 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 ); -- 1.7.1