From: Guilherme Maciel Ferreira Date: Thu, 21 Apr 2011 09:29:37 +0000 (+0200) Subject: Fixed some issues issued by PC-lint X-Git-Tag: v1.0~66 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=d496d45ce63f76caf12df16ce7ccccccecafdbff;p=pingcheck Fixed some issues issued by PC-lint --- diff --git a/src/icmp/icmpheader.cpp b/src/icmp/icmpheader.cpp index a0da95d..d4166be 100644 --- a/src/icmp/icmpheader.cpp +++ b/src/icmp/icmpheader.cpp @@ -121,6 +121,7 @@ void IcmpHeader::set_icmp_message_format( IcmpType type ) case IcmpType_InfoReply: case IcmpType_AddressRequest: case IcmpType_AddressReply: + case IcmpType_Generic: MessageFormat.reset( new IcmpGenericMessage ); break; case IcmpType_InvalidLast: diff --git a/src/icmp/icmpmessagepayload.cpp b/src/icmp/icmpmessagepayload.cpp index dbe0b17..36032a0 100644 --- a/src/icmp/icmpmessagepayload.cpp +++ b/src/icmp/icmpmessagepayload.cpp @@ -12,25 +12,32 @@ using boost::scoped_array; //----------------------------------------------------------------------------- IcmpMessagePayload::IcmpMessagePayload( - size_t payload_size_in_bytes + const std::size_t &payload_size_in_bytes ) : PayloadSizeInBytes( payload_size_in_bytes ), Payload( new uint8_t[ payload_size_in_bytes ] ) { + BOOST_ASSERT( 0 < payload_size_in_bytes ); + fill( Payload.get(), Payload.get() + PayloadSizeInBytes, 0 ); } IcmpMessagePayload::~IcmpMessagePayload() { + // Payload automatically delete by smart pointer scope end } const uint8_t& IcmpMessagePayload::operator[]( size_t offset ) const { + BOOST_ASSERT( offset < PayloadSizeInBytes ); + return Payload[ offset ]; } uint8_t& IcmpMessagePayload::operator[]( size_t offset ) { + BOOST_ASSERT( offset < PayloadSizeInBytes ); + return Payload[ offset ]; } @@ -39,9 +46,9 @@ uint16_t IcmpMessagePayload::decode( const int right_byte ) const { - int value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ]; + uint32_t value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ]; - BOOST_ASSERT( ( 0 <= value ) && ( value <= numeric_limits::max() ) ); + BOOST_ASSERT( value <= numeric_limits::max() ); return static_cast ( value ); } @@ -59,9 +66,9 @@ void IcmpMessagePayload::encode( istream& IcmpMessagePayload::read( istream &is ) { char *data_array = reinterpret_cast ( Payload.get() ); - is.read( data_array, PayloadSizeInBytes ); + (void) is.read( data_array, PayloadSizeInBytes ); - BOOST_ASSERT( is.gcount() == PayloadSizeInBytes ); + BOOST_ASSERT( static_cast(is.gcount()) == PayloadSizeInBytes ); return is; } diff --git a/src/icmp/icmpmessagepayload.h b/src/icmp/icmpmessagepayload.h index 2ba14e6..eed2e52 100644 --- a/src/icmp/icmpmessagepayload.h +++ b/src/icmp/icmpmessagepayload.h @@ -6,8 +6,14 @@ #include #include +#include #include +#define NONCOPYABLE( Class ) \ + private: \ + Class( const Class & ); \ + Class & operator= ( const Class & ); + //----------------------------------------------------------------------------- // IcmpMessagePayload //----------------------------------------------------------------------------- @@ -15,7 +21,7 @@ class IcmpMessagePayload { public: - IcmpMessagePayload( std::size_t payload_size_in_bytes ); + explicit IcmpMessagePayload( const std::size_t &payload_size_in_bytes ); ~IcmpMessagePayload(); const uint8_t& operator[]( std::size_t offset ) const; @@ -35,9 +41,10 @@ public: std::ostream& write( std::ostream &os ) const; private: - const int PayloadSizeInBytes; + const std::size_t PayloadSizeInBytes; boost::scoped_array Payload; + NONCOPYABLE( IcmpMessagePayload ) }; #endif /* ICMPMESSAGEPAYLOAD_H */ diff --git a/src/icmp/ipv4header.cpp b/src/icmp/ipv4header.cpp index 205b364..b1a2a5d 100644 --- a/src/icmp/ipv4header.cpp +++ b/src/icmp/ipv4header.cpp @@ -126,9 +126,9 @@ istream &operator>>( uint16_t Ipv4Header::decode( int left_byte, int right_byte ) const { - int value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ]; + uint32_t value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ]; - BOOST_ASSERT( ( 0 <= value ) && ( value <= numeric_limits::max() ) ); + BOOST_ASSERT( value <= numeric_limits::max() ); return static_cast ( value ); }