Fixed some issues issued by PC-lint
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 21 Apr 2011 09:29:37 +0000 (11:29 +0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 21 Apr 2011 09:29:37 +0000 (11:29 +0200)
src/icmp/icmpheader.cpp
src/icmp/icmpmessagepayload.cpp
src/icmp/icmpmessagepayload.h
src/icmp/ipv4header.cpp

index a0da95d..d4166be 100644 (file)
@@ -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:
index dbe0b17..36032a0 100644 (file)
@@ -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<uint16_t>::max() ) );
+    BOOST_ASSERT( value <= numeric_limits<uint16_t>::max() );
 
     return static_cast<uint16_t> ( value );
 }
@@ -59,9 +66,9 @@ void IcmpMessagePayload::encode(
 istream& IcmpMessagePayload::read( istream &is )
 {
     char *data_array = reinterpret_cast<char *> ( Payload.get() );
-    is.read( data_array, PayloadSizeInBytes );
+    (void) is.read( data_array, PayloadSizeInBytes );
 
-    BOOST_ASSERT( is.gcount() == PayloadSizeInBytes );
+    BOOST_ASSERT( static_cast<size_t>(is.gcount()) == PayloadSizeInBytes );
 
     return is;
 }
index 2ba14e6..eed2e52 100644 (file)
@@ -6,8 +6,14 @@
 #include <istream>
 #include <ostream>
 
+#include <boost/noncopyable.hpp>
 #include <boost/scoped_array.hpp>
 
+#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<uint8_t> Payload;
 
+    NONCOPYABLE( IcmpMessagePayload )
 };
 
 #endif /* ICMPMESSAGEPAYLOAD_H */
index 205b364..b1a2a5d 100644 (file)
@@ -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<uint16_t>::max() ) );
+    BOOST_ASSERT( value <= numeric_limits<uint16_t>::max() );
 
     return static_cast<uint16_t> ( value );
 }