From: Guilherme Maciel Ferreira Date: Sun, 21 Aug 2011 00:16:25 +0000 (-0300) Subject: Fixing some asserts with wrong ranges and reworking some comments X-Git-Tag: v1.1^2~9 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=e3180ff14416be55abff37da53077f4b9324b395;p=pingcheck Fixing some asserts with wrong ranges and reworking some comments --- diff --git a/src/host/messagepayload.cpp b/src/host/messagepayload.cpp index bcb522d..1626301 100644 --- a/src/host/messagepayload.cpp +++ b/src/host/messagepayload.cpp @@ -81,8 +81,12 @@ MessagePayload& MessagePayload::operator=( const MessagePayload &other ) } /** - * @brief The element access operator to provide access syntax like regular - * arrays. + * @brief Array Subscript Operator. + * + * The element access operator to provide access syntax like regular + * arrays. This version is used when this object is constant. + * + * @return A non-modifiable reference to the object indexed by the offset. */ const uint8_t& MessagePayload::operator[]( size_t offset ) const { @@ -92,8 +96,12 @@ const uint8_t& MessagePayload::operator[]( size_t offset ) const } /** - * @brief The element access operator to provide access syntax like regular - * arrays. + * @brief Array Subscript Operator. + * + * The element access operator to provide access syntax like regular + * arrays. This version is used by non-const objects. + * + * @return A modifiable reference to the object indexed by the offset. */ uint8_t& MessagePayload::operator[]( size_t offset ) { @@ -109,7 +117,7 @@ uint8_t& MessagePayload::operator[]( size_t offset ) * @param right_byte the index of the right byte * * @return a concatenation of the byte indexed by left_byte with the byte - * indexed by right_byte + * indexed by right_byte. */ uint16_t MessagePayload::decode16( const int left_byte, @@ -119,7 +127,7 @@ uint16_t MessagePayload::decode16( BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( left_byte < right_byte ); - BOOST_ASSERT( ( right_byte - left_byte ) == sizeof(uint16_t) ); + BOOST_ASSERT( ( ( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) ); uint32_t value = static_cast( Payload[ left_byte ] << 8 ); value += static_cast( Payload[ right_byte ] ); @@ -145,10 +153,10 @@ void MessagePayload::encode16( const uint16_t value ) { - BOOST_ASSERT( ( 0 < left_byte ) && ( left_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( ( 0 < right_byte ) && ( right_byte < static_cast(PayloadSizeInBytes) ) ); + BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast(PayloadSizeInBytes) ) ); + BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( left_byte < right_byte ); - BOOST_ASSERT( ( right_byte - left_byte ) == sizeof(uint16_t) ); + BOOST_ASSERT( ( ( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) ); Payload[ left_byte ] = static_cast( value >> 8 ); Payload[ right_byte ] = static_cast( value & 0xFF ); @@ -171,7 +179,7 @@ uint32_t MessagePayload::decode32( BOOST_ASSERT( ( 0 <= first_byte ) && ( first_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( ( 0 <= last_byte ) && ( last_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( first_byte < last_byte ); - BOOST_ASSERT( ( last_byte - first_byte ) == sizeof(uint32_t) ); + BOOST_ASSERT( ( ( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) ); int current_byte = first_byte; @@ -205,7 +213,7 @@ void MessagePayload::encode32( BOOST_ASSERT( ( 0 < first_byte ) && ( first_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( ( 0 < last_byte ) && ( last_byte < static_cast(PayloadSizeInBytes) ) ); BOOST_ASSERT( first_byte < last_byte ); - BOOST_ASSERT( ( last_byte - first_byte ) == sizeof(uint32_t) ); + BOOST_ASSERT( ( ( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) ); int current_byte = first_byte;