PC-Lint warnings fixed:
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Wed, 21 Dec 2011 09:56:43 +0000 (07:56 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Wed, 21 Dec 2011 10:03:59 +0000 (08:03 -0200)
- Info 766: Header file 'limits' not used in module;
- Warning 534: Ignoring return value of functions 'MessagePayload::read(...)' and 'std::basic_istream<char>::read(char *, int)';
- Info 737: Loss of sign in promotion from int to unsigned int;
- Info 713: Loss of precision (initialization) (unsigned int to int);
- Info 732: Loss of sign (arg. no. 2) (int to unsigned int) in 'header.Payload.append( options_data.get(), options_length )'.

src/ip/ipv4header.cpp

index e8e2cbf..7c13490 100644 (file)
@@ -6,13 +6,14 @@
 //          http://www.boost.org/LICENSE_1_0.txt)
 #include "ip/ipv4header.h"
 
-#include <limits>
-
 #include <boost/scoped_array.hpp>
 
+#include <logfunc.hpp>
+
 using namespace std;
 using boost::asio::ip::address_v4;
 using boost::scoped_array;
+using I2n::Logger::GlobalLogger;
 
 //-----------------------------------------------------------------------------
 // Ipv4Header
@@ -214,29 +215,32 @@ istream &operator>>(
 {
     // read the first 20 bytes (mandatory for IP header) from the input stream
     // and stores in the buffer object
-    header.Payload.read( is );
+    (void) header.Payload.read( is );
 
     if ( header.get_version() != 4 )
     {
+        GlobalLogger.error() << "Error: invalid IP header version." << endl;
         is.setstate( ios::failbit );
     }
 
     // read the consecutive N bytes (for options field) from the input stream
     // and stores in the buffer object
-    streamsize options_length = (streamsize) header.get_header_length() -
-                                Ipv4HeaderSizeInBytes;
+    streamsize options_length = static_cast<streamsize>( header.get_header_length() ) -
+                                static_cast<streamsize>( Ipv4HeaderSizeInBytes );
     if ( ( options_length < 0 ) || ( 40 < options_length ) )
     {
+        GlobalLogger.error() << "Error: invalid IP options length value." << endl;
         is.setstate( ios::failbit );
     }
     else
     {
-        scoped_array<uint8_t> options_data(new uint8_t[options_length]);
+        size_t options_size = static_cast<size_t>( options_length );
+        scoped_array<uint8_t> options_data( new uint8_t[options_size] );
         char *options_data_array = reinterpret_cast<char *>( options_data.get() );
 
-        is.read( options_data_array, options_length );
+        (void) is.read( options_data_array, options_length );
 
-        header.Payload.append( options_data.get(), options_length );
+        header.Payload.append( options_data.get(), options_size );
     }
 
     return is;